Skip to main content

DepsError

Enum DepsError 

Source
#[non_exhaustive]
pub enum DepsError {
Show 16 variants ParseError { file_type: String, source: Box<dyn Error + Send + Sync>, }, RegistryError { package: RedactedUrl, source: SanitizedRegistryError, }, CacheError(String), RateLimited { message: String, }, PackageNotFound { package: RedactedName, registry: &'static str, }, HttpStatus { url: RedactedUrl, status: u16, }, ApiResponse { package: RedactedName, registry: &'static str, source: Error, }, ResponseTooLarge { url: RedactedUrl, limit: usize, }, InvalidVersionReq(String), Io(Error), Json(Error), UnsupportedEcosystem(String), AmbiguousEcosystem(String), InvalidUri(String), Offline { url: RedactedUrl, }, ChainResolutionHalted,
}
Expand description

Core error types for deps-lsp.

Extended from Phase 1 to support multiple ecosystems (Cargo, npm, PyPI). All errors provide structured error handling with source error tracking.

§Examples

use deps_core::error::{DepsError, Result};

fn parse_file(content: &str, file_type: &str) -> Result<()> {
    // Parsing errors are automatically wrapped
    if content.is_empty() {
        return Err(DepsError::ParseError {
            file_type: file_type.into(),
            source: Box::new(std::io::Error::new(
                std::io::ErrorKind::InvalidData,
                "empty content"
            )),
        });
    }
    Ok(())
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

ParseError

A manifest or lockfile failed to parse.

Fields

§file_type: String

Ecosystem/file kind being parsed (e.g. "Cargo.toml"), for the error message.

§source: Box<dyn Error + Send + Sync>

The underlying parser error.

§

RegistryError

A registry HTTP request failed at the transport layer.

Fields

§package: RedactedUrl

Name of the package the request was for — or, at several deps-core::cache call sites, the request URL instead (see RedactedUrl’s own docs). Redaction is safe to apply unconditionally: a genuine URL is redacted for real, and a genuine package name is left alone unless it happens to contain a : or a non-leading @ (a leading @, e.g. an npm-scoped name like @types/node, is left untouched), in which case it is redacted the same way a credential-bearing value would be (e.g. a Maven/Gradle group:artifact coordinate becomes group:***) — a cosmetic false positive, never a correctness issue, since no current call site populates this field with a coordinate (only cache.rs does, always with a URL).

§source: SanitizedRegistryError

The underlying reqwest error, with its embedded request URL stripped.

§

CacheError(String)

The cache layer itself failed (e.g. a poisoned lock), independent of any registry request.

§

RateLimited

A registry request was rejected for exceeding a rate limit. Unlike other variants, message is a pre-vetted, IP-free, actionable hint safe to surface verbatim in a per-dependency diagnostic (see Self::fetch_failure) — never build one from a raw registry error body, which can embed the caller’s public IP (github.rs:332-346).

Fields

§message: String

Pre-vetted, IP-free message safe to surface verbatim in a diagnostic.

§

PackageNotFound

A package name was not found on the given registry.

Fields

§package: RedactedName

Name of the package that was looked up — stored redacted (#1209): the raw value is unreachable from this field’s type.

§registry: &'static str

Name of the registry that reported the package as missing.

§

HttpStatus

A registry HTTP request returned a non-success status code.

Fields

§url: RedactedUrl

URL that was requested — stored redacted (#789): the raw value is unreachable from this field’s type.

§status: u16

HTTP status code returned.

§

ApiResponse

A registry’s response body failed to deserialize as JSON.

Fields

§package: RedactedName

Name of the package whose response failed to parse — stored redacted (#1209): the raw value is unreachable from this field’s type.

§registry: &'static str

Name of the registry the response came from.

§source: Error

The underlying JSON deserialization error.

§

ResponseTooLarge

A response body exceeded the configured size cap and was rejected before full download.

Fields

§url: RedactedUrl

URL the oversized response came from — stored redacted (#789): the raw value is unreachable from this field’s type.

§limit: usize

The size cap, in bytes, that was exceeded.

§

InvalidVersionReq(String)

Deliberately shared between two distinct rejection kinds: malformed version-requirement strings (all ecosystems) and malformed Go module paths (deps-go, which has no separate variant for the latter — see its validate_module_path). Nothing in the workspace discriminates on this variant beyond rendering its message, so a consumer-specific split was deferred (#399).

§

Io(Error)

A filesystem I/O operation failed.

§

Json(Error)

A JSON parsing operation failed outside of a registry response context.

§

UnsupportedEcosystem(String)

The manifest file’s ecosystem could not be determined from any registered router.

§

AmbiguousEcosystem(String)

More than one ecosystem’s routing rules matched the same manifest path.

§

InvalidUri(String)

A URI supplied by the client or a manifest could not be parsed.

§

Offline

Returned by deps_core::cache::HttpCache’s 4 send sites (issue #483) when network.offline is set, instead of attempting the request. url is the request that was blocked, for diagnostic/logging purposes.

Fields

§url: RedactedUrl

The request URL that was blocked — stored redacted (#789): the raw value is unreachable from this field’s type.

§

ChainResolutionHalted

A multi-hop alternate/private-index chain’s resolution was halted because a hop returned a genuine transport error (5xx, timeout, connection failure) rather than a clean “not found” — the chain deliberately does not fall through to a further, less trusted hop in this case (deps_pypi’s FR-005(c)/NFR-003(3), #513). Carries no arbitrary error text — mirrors Self::RateLimited’s pre-vetted-message precedent (see Self::fetch_failure’s security-load-bearing invariant) — so its classification there can safely be FetchFailure::Actionable with a fixed, safe message, surfacing this case in hover/diagnostics instead of only a tracing::warn!.

Implementations§

Source§

impl DepsError

Source

pub const fn is_not_found(&self) -> bool

Returns true when this error means the registry was successfully asked and answered “this package doesn’t exist”, as opposed to the registry not having been answerable at all (network failure, timeout, malformed response, 5xx).

Distinguishing the two matters for diagnostics (#267): a genuine not-found is evidence the package name is wrong, while any other error is evidence only that this particular request failed — reporting the latter as “Unknown package” would mislabel a transient registry outage as a nonexistent dependency. Covers DepsError::PackageNotFound (the ecosystems that map a 404 to it explicitly: npm, PyPI, Go, Swift) and a bare DepsError::HttpStatus with status == 404 (the ecosystems that propagate the raw HTTP status instead: Cargo, Maven, Gradle, Bundler, Dart, Composer, NuGet).

§Examples
use deps_core::DepsError;

let not_found = DepsError::PackageNotFound {
    package: "left-pad".into(),
    registry: "npm",
};
assert!(not_found.is_not_found());

let http_404 = DepsError::HttpStatus {
    url: "https://crates.io/api/v1/crates/left-pad".into(),
    status: 404,
};
assert!(http_404.is_not_found());

let outage = DepsError::HttpStatus {
    url: "https://crates.io/api/v1/crates/serde".into(),
    status: 503,
};
assert!(!outage.is_not_found());

let cache_err = DepsError::CacheError("connection reset".into());
assert!(!cache_err.is_not_found());
Source

pub fn fetch_failure(&self) -> FetchFailure

Classifies this error for the per-dependency “registry lookup failed” diagnostic (#478), distinguishing a failure with a safe, actionable hint to show the user from one whose raw text must never reach a diagnostic.

Security-load-bearing invariant: FetchFailure::Actionable is produced only from Self::RateLimited’s pre-vetted, IP-free canned message. Every other variant must classify as FetchFailure::Transient — never call .to_string()/Display on an arbitrary DepsError to build an Actionable value, since a raw HttpStatus or RegistryError body can embed the caller’s public IP (github.rs:332-346, exercised by the github crate’s test_parse_tags_page_github_rate_limit_returns_error).

§Examples
use deps_core::error::{DepsError, FetchFailure};

let rate_limited = DepsError::RateLimited { message: "set GITHUB_TOKEN".into() };
assert_eq!(
    rate_limited.fetch_failure(),
    FetchFailure::Actionable("set GITHUB_TOKEN".into())
);

let other = DepsError::CacheError("connection reset".into());
assert_eq!(other.fetch_failure(), FetchFailure::Transient);
Source

pub const fn is_offline(&self) -> bool

Returns true when this error means a request was blocked by network.offline (issue #483), as opposed to any other network or registry failure.

Used by deps_maven::registry to skip poisoning its negative-search-failure cache with an offline block, so toggling network.offline back to false takes effect immediately instead of being masked by RECENT_FAILURE_TTL.

§Examples
use deps_core::DepsError;

let offline = DepsError::Offline { url: "https://crates.io/".into() };
assert!(offline.is_offline());

let other = DepsError::CacheError("connection reset".into());
assert!(!other.is_offline());

Trait Implementations§

Source§

impl Debug for DepsError

Hand-written, not derived: originally because a derived Debug would have printed HttpStatus.url, Offline.url, ResponseTooLarge.url, and RegistryError.package raw and unredacted (#767 code-review follow-up) — any tracing::warn!(?err, ...)/{err:?} call site, a common and arguably more idiomatic alternative to %err, would have bypassed the hand-written Display text entirely and reintroduced the raw URL/query string. Since #789, those four fields are typed RedactedUrl directly, so a derived Debug would actually be safe too (each field’s own Debug already forwards to redacted text) — this impl is kept hand-written anyway as defense-in-depth against a future field-type regression, not because it is still load-bearing on its own. Every field is still shown (this is not a summary).

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DepsError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for DepsError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for DepsError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for DepsError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more