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

RollingFileAppender::new() panics if the file can't be opened #1953

Closed
lilyball opened this issue Feb 21, 2022 · 2 comments · Fixed by #2227
Closed

RollingFileAppender::new() panics if the file can't be opened #1953

lilyball opened this issue Feb 21, 2022 · 2 comments · Fixed by #2227
Labels
crate/appender Related to the `tracing-appender` crate. kind/feature New feature or request

Comments

@lilyball
Copy link
Contributor

Bug Report

Version

tracing-appender v0.2.0

Crates

tracing-appender

Description

tracing-appender panics if it can't create the writer. This happens if the file can't be opened for appending. For example, if I do tracing_appender::rolling::daily("/", "foo"), on macOS this panics with an IO error about "Read-only file system" (on other OSes I'd expect a permissions error if I'm not running as root).

Opening the file synchronously is a great idea, it means I can actually handle errors instead of having them just be printed to stderr, but this needs to actually be returned as a Result rather than panicking. This includes not just RollingFileAppender::new() but also the convenience functions (tracing_appender::rolling::{daily, hourly, minutely, never}). This is of course a breaking change.

@hawkw hawkw added crate/appender Related to the `tracing-appender` crate. kind/feature New feature or request labels Feb 21, 2022
@hawkw
Copy link
Member

hawkw commented Feb 21, 2022

I would consider changing the new constructor and friends to return a Result in the next breaking change. Alternatively, we could add a try_new1 constructor that returns a Result, and change the new constructor to call that and expect it. We could do this right away and not have to wait for other breaking changes.

Footnotes

  1. Name open to bikeshedding if anyone can think of something that sounds less awkward.

@lilyball
Copy link
Contributor Author

lilyball commented Mar 6, 2022

If a try_new is added it should be considered a workaround and deprecated in the next breaking change in favor of changing the constructors. I guess this depends on how long we can expect to wait before a breaking change to tracing-appender.

@davidbarsky davidbarsky added this to the tracing-appender 0.3 milestone Mar 24, 2022
hawkw added a commit that referenced this issue Jul 18, 2022
Several currently open PRs, such as #2225 and #2221, add new
configuration parameters to the rolling file appender in
`tracing-appender`. The best way to add new optional configuration
settings without breaking existing APIs or creating a very large number
of new constructors is to add a builder interface.

Since a number of PRs would all need to add the builder API, introducing
potential conflicts, this branch _just_ adds the builder interface
without adding any new configuration options. Once this merges, the
existing in-flight PRs can be rebased onto this branch to use the
builder interface without conflicting with each other.

Also, the `Builder::build` method is fallible and returns a `Result`,
rather than panicking. This is a relatively common pattern in Rust ---
for example, `std::thread::Builder::spawn` returns a `Result` if a new
thread cannot be spawned, while `std::thread::spawn` simply panics. This
allows users to handle appender initialization errors gracefully without
breaking the API of the existing `new` constructor.

Fixes #1953
hawkw added a commit that referenced this issue Jul 18, 2022
## Motivation

Several currently open PRs, such as #2225 and #2221, add new
configuration parameters to the rolling file appender in
`tracing-appender`. The best way to add new optional configuration
settings without breaking existing APIs or creating a very large number
of new constructors is to add a builder interface.

## Solution

Since a number of PRs would all need to add the builder API, introducing
potential conflicts, this branch _just_ adds the builder interface
without adding any new configuration options. Once this merges, the
existing in-flight PRs can be rebased onto this branch to use the
builder interface without conflicting with each other.

Also, the `Builder::build` method is fallible and returns a `Result`,
rather than panicking. This is a relatively common pattern in Rust ---
for example, `std::thread::Builder::spawn` returns a `Result` if a new
thread cannot be spawned, while `std::thread::spawn` simply panics. This
allows users to handle appender initialization errors gracefully without
breaking the API of the existing `new` constructor.

Fixes #1953

Signed-off-by: Eliza Weisman <[email protected]>
hawkw added a commit that referenced this issue Jul 20, 2022
## Motivation

Several currently open PRs, such as #2225 and #2221, add new
configuration parameters to the rolling file appender in
`tracing-appender`. The best way to add new optional configuration
settings without breaking existing APIs or creating a very large number
of new constructors is to add a builder interface.

## Solution

Since a number of PRs would all need to add the builder API, introducing
potential conflicts, this branch _just_ adds the builder interface
without adding any new configuration options. Once this merges, the
existing in-flight PRs can be rebased onto this branch to use the
builder interface without conflicting with each other.

Also, the `Builder::build` method is fallible and returns a `Result`,
rather than panicking. This is a relatively common pattern in Rust ---
for example, `std::thread::Builder::spawn` returns a `Result` if a new
thread cannot be spawned, while `std::thread::spawn` simply panics. This
allows users to handle appender initialization errors gracefully without
breaking the API of the existing `new` constructor.

Fixes #1953

Signed-off-by: Eliza Weisman <[email protected]>
hawkw added a commit that referenced this issue Jul 20, 2022
## Motivation

Several currently open PRs, such as #2225 and #2221, add new
configuration parameters to the rolling file appender in
`tracing-appender`. The best way to add new optional configuration
settings without breaking existing APIs or creating a very large number
of new constructors is to add a builder interface.

## Solution

Since a number of PRs would all need to add the builder API, introducing
potential conflicts, this branch _just_ adds the builder interface
without adding any new configuration options. Once this merges, the
existing in-flight PRs can be rebased onto this branch to use the
builder interface without conflicting with each other.

Also, the `Builder::build` method is fallible and returns a `Result`,
rather than panicking. This is a relatively common pattern in Rust ---
for example, `std::thread::Builder::spawn` returns a `Result` if a new
thread cannot be spawned, while `std::thread::spawn` simply panics. This
allows users to handle appender initialization errors gracefully without
breaking the API of the existing `new` constructor.

Fixes #1953

Signed-off-by: Eliza Weisman <[email protected]>
hawkw added a commit that referenced this issue Jul 20, 2022
## Motivation

Several currently open PRs, such as #2225 and #2221, add new
configuration parameters to the rolling file appender in
`tracing-appender`. The best way to add new optional configuration
settings without breaking existing APIs or creating a very large number
of new constructors is to add a builder interface.

## Solution

Since a number of PRs would all need to add the builder API, introducing
potential conflicts, this branch _just_ adds the builder interface
without adding any new configuration options. Once this merges, the
existing in-flight PRs can be rebased onto this branch to use the
builder interface without conflicting with each other.

Also, the `Builder::build` method is fallible and returns a `Result`,
rather than panicking. This is a relatively common pattern in Rust ---
for example, `std::thread::Builder::spawn` returns a `Result` if a new
thread cannot be spawned, while `std::thread::spawn` simply panics. This
allows users to handle appender initialization errors gracefully without
breaking the API of the existing `new` constructor.

Fixes #1953

Signed-off-by: Eliza Weisman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/appender Related to the `tracing-appender` crate. kind/feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants