Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return HttpInvalid error instead of FastlyStatus::Error when failed to build Uri #378

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arayaryoma
Copy link

Fastly Rust SDK maps FastlyStatus::Error to BackendCreationError::NameInUse.
By this, when we passed invalid host name value to fastly::Backend::builder func, we always received NameInUse error.
It's a misleading behavior for developers, who will assume they register the same backend multiple times.

In this PR, I defined a new internal Error InvalidBackendUrl and map it as FastlyStatus::HttpInvalid.
It will help developers to awake they are using invalid URI to build the dynamic backend.

Example

before

let backend = match fastly::Backend::builder("example", "http://example.com").finish() {
    Ok(backend) => backend,
    Err(e) => {
        println!("Error: {:?}", e); // Error: NameInUse
        return Err(e);
    }
};

after

let backend = match fastly::Backend::builder("example", "http://example.com").finish() {
    Ok(backend) => backend,
    Err(e) => {
        println!("Error: {:?}", e); // Error: HostError(FastlyStatus::HTTP_INVALID_ERROR)
        return Err(e);
    }
};

…o build Uri

Fastly Rust SDK maps `FastlyStatus::Error` to `BackendCreationError::NameInUse`.
It's a misleading behavior for developers, who will assume they
register the same backend multitimes
@kpfleming
Copy link
Contributor

kpfleming commented Jul 26, 2024

This is going in a good direction, but the name of the error itself seems incorrect: the parameter to the backend builder is not a URL, so the error cannot indicate that the user provided an 'invalid backend URL' (even though the provided value is used in constructing a URL). Should it be InvalidBackendSpecification or something similar?

Edit: I realize this is internal to Viceroy, but I'd still prefer the name to be accurate for the benefit of future readers of the code. It would also be nice if we had a better FastlyStatus value to map it into, but we don't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants