Skip to content

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