Skip to content

Commit 02dda12

Browse files
mitsuhikojan-auer
authored andcommitted
feat: 2018 edition fixes and various cleanups. (#116)
1 parent e520d1b commit 02dda12

26 files changed

+154
-185
lines changed

.travis.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ matrix:
1818
- env: SUITE=format-check
1919
- env: SUITE=lint
2020
- env: SUITE=check
21-
rust: "1.30.0"
21+
rust: "1.31.0"
2222
- env: SUITE=cargotest
23-
rust: "1.30.0"
23+
rust: "1.31.0"
2424
- env: SUITE=checkall
2525
- env: SUITE=cargotestall
2626
- os: osx
@@ -29,10 +29,6 @@ matrix:
2929
env: SUITE=cargotestall
3030
- env: SUITE=travis-push-docs
3131

32-
allow_failures:
33-
- env: SUITE=format-check
34-
- env: SUITE=lint
35-
3632
notifications:
3733
webhooks:
3834
urls:

Cargo.toml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ description = """
1111
Sentry (getsentry.com) client for rust ;)
1212
"""
1313
build = "build.rs"
14+
autoexamples = true
1415

1516
[package.metadata.docs.rs]
1617
all-features = true
@@ -67,25 +68,5 @@ actix-web = { version = "0.7.17", default-features = false }
6768
name = "error-chain-demo"
6869
required-features = ["with_error_chain"]
6970

70-
# TODO: Remove these once autoexamples are stable
71-
[[example]]
72-
name = "failure-demo"
73-
[[example]]
74-
name = "log-demo"
75-
[[example]]
76-
name = "message-demo"
77-
[[example]]
78-
name = "panic-demo"
79-
[[example]]
80-
name = "thread-demo"
81-
[[example]]
82-
name = "init-with-client"
83-
[[example]]
84-
name = "event-processors"
85-
[[example]]
86-
name = "before-send"
87-
[[example]]
88-
name = "send-with-extra"
89-
9071
[workspace]
9172
members = [".", "integrations/sentry-actix"]

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ test: checkall cargotestall
7878
.PHONY: test
7979

8080
format-check:
81-
@rustup component add rustfmt-preview 2> /dev/null
81+
@rustup component add rustfmt 2> /dev/null
8282
@cargo fmt -- --check
8383
.PHONY: format-check
8484

8585
lint:
86-
@rustup component add clippy-preview 2> /dev/null
87-
@cargo clippy --all-features --tests --all --examples -- -D clippy
86+
@rustup component add clippy 2> /dev/null
87+
@cargo clippy --all-features --tests --all --examples -- -D clippy::all
8888
.PHONY: lint
8989

9090
travis-push-docs:

examples/log-demo.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#[macro_use]
21
extern crate log;
32
extern crate pretty_env_logger;
4-
#[macro_use]
53
extern crate sentry;
64

5+
use log::{debug, error, info, warn};
6+
use sentry::sentry_crate_release;
7+
78
fn main() {
89
let _sentry = sentry::init((
910
"https://[email protected]/1041156",

integrations/sentry-actix/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ We currently only verify this crate against a recent version of Sentry hosted on
1818
[sentry.io](https://sentry.io/) but it should work with on-prem Sentry versions
1919
8.20 and later.
2020

21-
Additionally, the lowest Rust version we target is _1.24.0_.
21+
Additionally, the lowest Rust version we target is _1.31.0_.
2222

2323
## Resources
2424

25-
* [crates.io](https://crates.io/crate/sentry)
26-
* [Documentation](https://docs.rs/sentry)
27-
* [Bug Tracker](https://github.com/getsentry/sentry-rust/issues)
28-
* [IRC](irc://chat.freenode.net/sentry) (chat.freenode.net, #sentry)
29-
* Follow [@getsentry](https://twitter.com/getsentry) on Twitter for updates
25+
- [crates.io](https://crates.io/crate/sentry)
26+
- [Documentation](https://docs.rs/sentry)
27+
- [Bug Tracker](https://github.com/getsentry/sentry-rust/issues)
28+
- [IRC](irc://chat.freenode.net/sentry) (chat.freenode.net, #sentry)
29+
- Follow [@getsentry](https://twitter.com/getsentry) on Twitter for updates

integrations/sentry-actix/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,17 @@ extern crate failure;
7979
extern crate fragile;
8080
extern crate sentry;
8181

82+
use std::borrow::Cow;
83+
use std::cell::RefCell;
84+
use std::sync::{Arc, Mutex};
85+
8286
use actix_web::middleware::{Finished, Middleware, Response, Started};
8387
use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse};
8488
use failure::Fail;
8589
use sentry::integrations::failure::exception_from_single_fail;
86-
use sentry::internals::ScopeGuard;
90+
use sentry::internals::{ScopeGuard, Uuid};
8791
use sentry::protocol::{ClientSdkPackage, Event, Level};
88-
use sentry::{Hub, Uuid};
89-
use std::borrow::Cow;
90-
use std::cell::RefCell;
91-
use std::sync::{Arc, Mutex};
92+
use sentry::Hub;
9293

9394
/// A helper construct that can be used to reconfigure and build the middleware.
9495
pub struct SentryMiddlewareBuilder {

src/api.rs

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
1-
use api::protocol::Event;
2-
3-
// public api from other crates
4-
pub use sentry_types::protocol::v7 as protocol;
5-
pub use sentry_types::protocol::v7::{Breadcrumb, Level, User};
6-
pub use sentry_types::{
7-
ChronoParseError, DateTime, DebugId, Dsn, ParseDebugIdError, TimeZone, Utc, Uuid, UuidVariant,
8-
UuidVersion,
9-
};
10-
11-
// public exports from this crate
121
#[cfg(feature = "with_client_implementation")]
13-
pub use client::{init, Client, ClientOptions};
14-
pub use hub::Hub;
15-
pub use scope::Scope;
2+
use crate::hub::Hub;
3+
use crate::scope::Scope;
164

17-
use hub::IntoBreadcrumbs;
18-
19-
/// Useful internals.
20-
///
21-
/// This module contains types that users of the create typically do not
22-
/// have to directly interface with directly. These are often returned
23-
/// from methods on other types.
24-
pub mod internals {
25-
#[cfg(feature = "with_client_implementation")]
26-
pub use client::{ClientInitGuard, IntoDsn};
27-
pub use hub::IntoBreadcrumbs;
28-
pub use scope::ScopeGuard;
29-
pub use sentry_types::{Auth, DsnParseError, ProjectId, ProjectIdParseError, Scheme};
30-
#[cfg(feature = "with_client_implementation")]
31-
pub use transport::{DefaultTransportFactory, HttpTransport, Transport, TransportFactory};
32-
}
5+
use crate::hub::IntoBreadcrumbs;
6+
use crate::internals;
7+
use crate::protocol::{Event, Level};
338

349
/// Captures an event on the currently active client if any.
3510
///
@@ -50,7 +25,7 @@ pub mod internals {
5025
/// });
5126
/// ```
5227
#[allow(unused_variables)]
53-
pub fn capture_event(event: Event<'static>) -> Uuid {
28+
pub fn capture_event(event: Event<'static>) -> internals::Uuid {
5429
with_client_impl! {{
5530
Hub::with(|hub| hub.capture_event(event))
5631
}}
@@ -60,7 +35,7 @@ pub fn capture_event(event: Event<'static>) -> Uuid {
6035
///
6136
/// This creates an event form the given message and sends it to the current hub.
6237
#[allow(unused_variables)]
63-
pub fn capture_message(msg: &str, level: Level) -> Uuid {
38+
pub fn capture_message(msg: &str, level: Level) -> internals::Uuid {
6439
with_client_impl! {{
6540
Hub::with_active(|hub| {
6641
hub.capture_message(msg, level)
@@ -189,7 +164,7 @@ where
189164
}
190165

191166
/// Returns the last event ID captured.
192-
pub fn last_event_id() -> Option<Uuid> {
167+
pub fn last_event_id() -> Option<internals::Uuid> {
193168
with_client_impl! {{
194169
Hub::with_active(|hub| {
195170
hub.last_event_id()

src/backtrace_support.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33
use backtrace::Backtrace;
44
use regex::{Captures, Regex};
55

6-
use api::protocol::{Frame, Stacktrace};
6+
use crate::protocol::{Frame, Stacktrace};
77

88
lazy_static! {
99
static ref HASH_FUNC_RE: Regex = Regex::new(r#"(?x)

src/client.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::borrow::Cow;
2-
use std::env;
32
use std::ffi::{OsStr, OsString};
43
use std::fmt;
54
use std::panic::RefUnwindSafe;
@@ -10,15 +9,14 @@ use std::time::Duration;
109
use rand::random;
1110
use regex::Regex;
1211

13-
use api::protocol::{Breadcrumb, DebugMeta, Event};
14-
use api::{Dsn, Uuid};
15-
use backtrace_support::{function_starts_with, is_sys_function, trim_stacktrace};
16-
use constants::{SDK_INFO, USER_AGENT};
17-
use hub::Hub;
18-
use internals::DsnParseError;
19-
use scope::Scope;
20-
use transport::{DefaultTransportFactory, Transport, TransportFactory};
21-
use utils::{debug_images, server_name};
12+
use crate::backtrace_support::{function_starts_with, is_sys_function, trim_stacktrace};
13+
use crate::constants::{SDK_INFO, USER_AGENT};
14+
use crate::hub::Hub;
15+
use crate::internals::{Dsn, DsnParseError, Uuid};
16+
use crate::protocol::{Breadcrumb, DebugMeta, Event};
17+
use crate::scope::Scope;
18+
use crate::transport::{DefaultTransportFactory, Transport, TransportFactory};
19+
use crate::utils;
2220

2321
/// The Sentry client object.
2422
pub struct Client {
@@ -175,7 +173,7 @@ impl Default for ClientOptions {
175173
fn default() -> ClientOptions {
176174
ClientOptions {
177175
// any invalid dsn including the empty string disables the dsn
178-
dsn: env::var("SENTRY_DSN")
176+
dsn: std::env::var("SENTRY_DSN")
179177
.ok()
180178
.and_then(|dsn| dsn.parse::<Dsn>().ok()),
181179
transport: Box::new(DefaultTransportFactory),
@@ -190,15 +188,15 @@ impl Default for ClientOptions {
190188
} else {
191189
"release".into()
192190
}),
193-
server_name: server_name().map(Cow::Owned),
191+
server_name: utils::server_name().map(Cow::Owned),
194192
sample_rate: 1.0,
195193
user_agent: Cow::Borrowed(&USER_AGENT),
196-
http_proxy: env::var("http_proxy").ok().map(Cow::Owned),
197-
https_proxy: env::var("https_proxy")
194+
http_proxy: std::env::var("http_proxy").ok().map(Cow::Owned),
195+
https_proxy: std::env::var("https_proxy")
198196
.ok()
199197
.map(Cow::Owned)
200-
.or_else(|| env::var("HTTPS_PROXY").ok().map(Cow::Owned))
201-
.or_else(|| env::var("http_proxy").ok().map(Cow::Owned)),
198+
.or_else(|| std::env::var("HTTPS_PROXY").ok().map(Cow::Owned))
199+
.or_else(|| std::env::var("http_proxy").ok().map(Cow::Owned)),
202200
shutdown_timeout: Duration::from_secs(2),
203201
debug: false,
204202
attach_stacktrace: false,
@@ -352,11 +350,9 @@ impl Client {
352350
/// If the DSN on the options is set to `None` the client will be entirely
353351
/// disabled.
354352
pub fn with_options(options: ClientOptions) -> Client {
355-
#[cfg_attr(feature = "cargo-clippy", allow(question_mark))]
356-
let transport = RwLock::new(if options.dsn.is_none() {
357-
None
358-
} else {
359-
Some(Arc::new(options.transport.create_transport(&options)))
353+
let transport = RwLock::new(match options.dsn {
354+
Some(_) => Some(Arc::new(options.transport.create_transport(&options))),
355+
None => None,
360356
});
361357
Client { options, transport }
362358
}
@@ -383,15 +379,15 @@ impl Client {
383379
}
384380
}
385381

386-
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
382+
#[allow(clippy::cyclomatic_complexity)]
387383
fn prepare_event(
388384
&self,
389385
mut event: Event<'static>,
390386
scope: Option<&Scope>,
391387
) -> Option<Event<'static>> {
392388
lazy_static! {
393389
static ref DEBUG_META: DebugMeta = DebugMeta {
394-
images: debug_images(),
390+
images: utils::debug_images(),
395391
..Default::default()
396392
};
397393
}

src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use api::protocol::{ClientSdkInfo, ClientSdkPackage};
1+
use crate::protocol::{ClientSdkInfo, ClientSdkPackage};
22

33
/// The version of the library
44
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

src/hub.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
#![allow(unused)]
22

33
use std::cell::{Cell, UnsafeCell};
4-
use std::iter;
54
use std::mem::drop;
65
use std::sync::atomic::{AtomicBool, Ordering};
76
use std::sync::{Arc, Mutex, RwLock, TryLockError};
87
use std::thread;
98
use std::time::Duration;
109

11-
use api::Uuid;
12-
#[cfg(feature = "with_client_implementation")]
13-
use client::Client;
14-
use protocol::{Breadcrumb, Event, Level};
15-
#[cfg(feature = "with_client_implementation")]
16-
use scope::Stack;
17-
use scope::{Scope, ScopeGuard};
10+
use crate::internals::Uuid;
11+
use crate::protocol::{Breadcrumb, Event, Level};
12+
use crate::scope::{Scope, ScopeGuard};
13+
1814
#[cfg(feature = "with_client_implementation")]
19-
use utils::current_thread;
15+
use crate::{client::Client, scope::Stack, utils};
2016

2117
#[cfg(feature = "with_client_implementation")]
2218
lazy_static! {
@@ -25,6 +21,7 @@ lazy_static! {
2521
thread::current().id()
2622
);
2723
}
24+
2825
#[cfg(feature = "with_client_implementation")]
2926
thread_local! {
3027
static THREAD_HUB: UnsafeCell<Arc<Hub>> = UnsafeCell::new(
@@ -42,10 +39,10 @@ pub trait IntoBreadcrumbs {
4239
}
4340

4441
impl IntoBreadcrumbs for Breadcrumb {
45-
type Output = iter::Once<Breadcrumb>;
42+
type Output = std::iter::Once<Breadcrumb>;
4643

4744
fn into_breadcrumbs(self) -> Self::Output {
48-
iter::once(self)
45+
std::iter::once(self)
4946
}
5047
}
5148

@@ -220,7 +217,7 @@ impl Hub {
220217

221218
/// Binds a hub to the current thread for the duration of the call.
222219
#[cfg(feature = "with_client_implementation")]
223-
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
220+
#[allow(clippy::needless_pass_by_value)]
224221
pub fn run<F: FnOnce() -> R, R>(hub: Arc<Hub>, f: F) -> R {
225222
let mut restore_process_hub = false;
226223
let did_switch = THREAD_HUB.with(|ctx| unsafe {
@@ -300,7 +297,7 @@ impl Hub {
300297
..Default::default()
301298
};
302299
if client.options().attach_stacktrace {
303-
let thread = current_thread(true);
300+
let thread = utils::current_thread(true);
304301
if thread.stacktrace.is_some() {
305302
event.threads.values.push(thread);
306303
}

src/integrations/env_logger.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
//! log_builder.parse("info,foo=debug");
2424
//! sentry::integrations::env_logger::init(Some(log_builder.build()), Default::default());
2525
//! ```
26-
use env_logger;
27-
28-
use integrations::log::{self as sentry_log, LoggerOptions};
26+
use crate::integrations::log::{self as sentry_log, LoggerOptions};
2927

3028
/// Initializes the environment logger.
3129
///

src/integrations/error_chain.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ use std::fmt::{Debug, Display};
2828

2929
use error_chain::ChainedError;
3030

31-
use api::protocol::{Event, Exception, Level};
32-
use api::Uuid;
33-
use backtrace_support::{backtrace_to_stacktrace, error_typename};
34-
use hub::Hub;
31+
use crate::backtrace_support::{backtrace_to_stacktrace, error_typename};
32+
use crate::hub::Hub;
33+
use crate::internals::Uuid;
34+
use crate::protocol::{Event, Exception, Level};
3535

3636
fn exceptions_from_error_chain<T>(error: &T) -> Vec<Exception>
3737
where

0 commit comments

Comments
 (0)