Skip to content

Conversation

@kivikakk
Copy link
Contributor

This is a minor change which makes working with Nix a little bit easier.

write_metadata/2 passes a failed file write to its caller, __using__/2, which logs it as a warning. This is great, but on Nix the File.mkdir_p/1 fails before we get there, and currently this causes the whole process to abort.

This PR just forwards any error from File.mkdir_p/1 to the caller instead of raising a MatchError.

@philss
Copy link
Owner

philss commented Mar 10, 2025

@kivikakk thank you for the PR! This makes sense to me. Can you please run mix format, so it passes the linter?

Also, there is another way to write the same thing you did with the with macro:

with :ok <- File.mkdir_p(dir) do
  File.write(metadata_file, inspect(metadata, limit: :infinity, pretty: true))
end

This means that if the match is unsuccessful, the code will return whatever the result of the expression is.

@kivikakk kivikakk force-pushed the metadata-mkdir-fail-ok branch from 5c3f0bd to d6a3424 Compare March 10, 2025 23:17
@kivikakk
Copy link
Contributor Author

@kivikakk thank you for the PR! This makes sense to me. Can you please run mix format, so it passes the linter?

Also, there is another way to write the same thing you did with the with macro:

Thank you! I've used that (and run mix format).

@philss philss merged commit c7705b8 into philss:main Mar 11, 2025
3 checks passed
@kivikakk
Copy link
Contributor Author

Ta! :)

@kivikakk kivikakk deleted the metadata-mkdir-fail-ok branch March 12, 2025 04:26
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