CLI app for developers prototyping atproto functionality
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clean up lints after refactor

+39 -22
+1 -1
src/commands/test/oauth/client/pipeline/discovery.rs
··· 226 226 Box::new(JsonParseError { 227 227 source: named_source_from_bytes( 228 228 format!("metadata document (content-type: {ct})"), 229 - &pretty_body, 229 + pretty_body, 230 230 ), 231 231 span, 232 232 message: format!(
+5 -5
src/commands/test/oauth/client/pipeline/metadata.rs
··· 495 495 Box::new(RawDocumentDeserializationError { 496 496 src: crate::common::diagnostics::named_source_from_bytes( 497 497 raw_source_name, 498 - &pretty_body, 498 + pretty_body, 499 499 ), 500 500 span, 501 501 message: format!("metadata document is not valid JSON: {json_err}"), ··· 523 523 524 524 // Pretty-print JSON once for all diagnostics. 525 525 let pretty_body = crate::common::diagnostics::pretty_json_for_display(bytes); 526 - let source = crate::common::diagnostics::named_source_from_bytes( 526 + let source = crate::common::diagnostics::named_source_from_slice( 527 527 raw_source_name, 528 528 &pretty_body, 529 529 ); ··· 540 540 ); 541 541 let diagnostic: Box<dyn miette::Diagnostic + Send + Sync> = 542 542 Box::new(ClientIdInvalidDiagnostic { 543 - src: crate::common::diagnostics::named_source_from_bytes( 543 + src: crate::common::diagnostics::named_source_from_slice( 544 544 raw_source_name, 545 545 &pretty_body, 546 546 ), ··· 568 568 ); 569 569 let diagnostic: Box<dyn miette::Diagnostic + Send + Sync> = 570 570 Box::new(ClientIdMismatchDiagnostic { 571 - src: crate::common::diagnostics::named_source_from_bytes( 571 + src: crate::common::diagnostics::named_source_from_slice( 572 572 raw_source_name, 573 573 &pretty_body, 574 574 ), ··· 953 953 let offset = quoted_span.offset() + 1 + err.byte_offset; 954 954 let span = SourceSpan::new(offset.into(), err.token.len()); 955 955 let src = 956 - crate::common::diagnostics::named_source_from_bytes( 956 + crate::common::diagnostics::named_source_from_slice( 957 957 raw_source_name, 958 958 &pretty_body, 959 959 );
+9 -6
src/common/diagnostics.rs
··· 34 34 } 35 35 36 36 /// Build a `NamedSource` from a name and raw bytes. 37 + pub(crate) fn named_source_from_bytes( 38 + name: impl AsRef<str>, 39 + bytes: Arc<[u8]>, 40 + ) -> NamedSource<Arc<[u8]>> { 41 + NamedSource::new(name, bytes) 42 + } 43 + 44 + /// Build a `NamedSource` from a name and a slice. 37 45 /// 38 46 /// The bytes are cloned into an `Arc<[u8]>` via miette's constructor, 39 47 /// so callers may drop the original slice after this returns. 40 - pub(crate) fn named_source_from_bytes( 48 + pub(crate) fn named_source_from_slice( 41 49 name: impl AsRef<str>, 42 50 bytes: &[u8], 43 51 ) -> NamedSource<Arc<[u8]>> { 44 52 NamedSource::new(name, Arc::<[u8]>::from(bytes)) 45 - } 46 - 47 - /// Build a `NamedSource` from a name and a UTF-8 string slice. 48 - pub(crate) fn named_source_from_str(name: impl AsRef<str>, text: &str) -> NamedSource<String> { 49 - NamedSource::new(name, text.to_string()) 50 53 } 51 54 52 55 /// Pretty-print `body` as JSON for display in a `NamedSource`.
+24 -10
src/common/jwt.rs
··· 12 12 use serde::{Deserialize, Serialize}; 13 13 use thiserror::Error; 14 14 15 - use crate::common::identity::{AnySignatureError, AnySigningKey}; 15 + use crate::common::identity::AnySigningKey; 16 16 17 17 #[cfg(test)] 18 - use crate::common::identity::{AnySignature, AnyVerifyingKey}; 18 + use crate::common::identity::{AnySignature, AnySignatureError, AnyVerifyingKey}; 19 19 20 20 /// Compact JWS header for atproto service-auth tokens. 21 21 /// ··· 68 68 pub jti: String, 69 69 } 70 70 71 - /// Errors from JWT encode/decode. 71 + /// Errors from JWT encode. 72 72 /// 73 73 /// **Not user-rendered:** these errors only surface inside tests and 74 74 /// library helpers. They deliberately do NOT derive `miette::Diagnostic` ··· 78 78 /// rendered to the user, they must wrap it in a stage-local diagnostic 79 79 /// with a proper `code = "labeler::..."` string. 80 80 #[derive(Debug, Error)] 81 + pub(crate) enum EncodeError { 82 + /// JSON serialization of header or claims failed (should not happen for 83 + /// well-formed structs). 84 + #[error("JSON encode failed")] 85 + JsonEncode(serde_json::Error), 86 + } 87 + 88 + /// Errors from JWT decode. 89 + /// 90 + /// **Not user-rendered:** these errors only surface inside tests and 91 + /// library helpers. They deliberately do NOT derive `miette::Diagnostic` 92 + /// with stable codes — the stage converts any failure into a 93 + /// `CreateReportStageError::Transport` or a specific check SpecViolation 94 + /// before rendering. If a future caller needs one of these variants 95 + /// rendered to the user, they must wrap it in a stage-local diagnostic 96 + /// with a proper `code = "labeler::..."` string. 97 + #[cfg(test)] 98 + #[derive(Debug, Error)] 81 99 pub(crate) enum JwtError { 82 100 /// Compact form was not three `.`-separated base64url segments. 83 101 #[error("malformed compact JWT: expected three segments")] ··· 100 118 #[source] 101 119 source: serde_json::Error, 102 120 }, 103 - /// JSON serialization of header or claims failed (should not happen for 104 - /// well-formed structs). 105 - #[error("JSON encode failed")] 106 - JsonEncode(serde_json::Error), 107 121 /// Signature was not exactly 64 bytes. 108 122 #[error("signature was {actual} bytes; expected 64")] 109 123 SignatureLength { ··· 133 147 header: &JwtHeader, 134 148 claims: &JwtClaims, 135 149 signer: &AnySigningKey, 136 - ) -> Result<String, JwtError> { 137 - let header_json = serde_json::to_vec(header).map_err(JwtError::JsonEncode)?; 138 - let claims_json = serde_json::to_vec(claims).map_err(JwtError::JsonEncode)?; 150 + ) -> Result<String, EncodeError> { 151 + let header_json = serde_json::to_vec(header).map_err(EncodeError::JsonEncode)?; 152 + let claims_json = serde_json::to_vec(claims).map_err(EncodeError::JsonEncode)?; 139 153 let header_b64 = URL_SAFE_NO_PAD.encode(&header_json); 140 154 let claims_b64 = URL_SAFE_NO_PAD.encode(&claims_json); 141 155 let signing_input = format!("{header_b64}.{claims_b64}");