Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: erlef/setup-beam@v1
with:
otp-version: "27"
gleam-version: "1.9.0"
gleam-version: "1.13.0"
rebar3-version: "3"
# elixir-version: "1.14.2"
- run: gleam test
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Changelog

- Add documentation for 'mode' field in FileInfo.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a docs update that doesn't affect the version number, so I think it shouldn't be in the changelog.


## Unreleased

## v2.3.2 - 26 December 2025
- Fix bug where unknown errors were not properly converted to the Unknown variant in Erlang ffi.

## v2.3.1 - 6 November 2025
- Fix bug with error string typo for `Enotdir` on JS.

Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "simplifile"
version = "2.3.1"
version = "2.3.2"
description = "Basic file operations that work on all targets"

licences = ["Apache-2.0"]
Expand Down
4 changes: 3 additions & 1 deletion src/simplifile_erl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ posix_result(Result) ->
{ok, Value} ->
{ok, Value};
{error, Reason} when ?is_posix_error(Reason) ->
{error, Reason}
{error, Reason};
{error, Reason} ->
{error, {unknown, string:uppercase(atom_to_binary(Reason))}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The atom_to_binary function defaults to utf8, so it should be fine to pass the resulting binary to string:uppercase

end.

%% Read the binary contents of a file
Expand Down
46 changes: 33 additions & 13 deletions test/simplifile_test.gleam
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import gleam/int
import gleam/list
import gleam/set
import gleam/string
import gleeunit
import gleeunit/should
import simplifile.{
Directory, Eacces, Eagain, Ebadf, Ebadmsg, Ebusy, Edeadlk, Edeadlock, Edquot,
Eexist, Efault, Efbig, Eftype, Einval, Eio, Eisdir, Eloop, Emfile, Emlink,
Emultihop, Enametoolong, Enfile, Enobufs, Enodev, Enoent, Enolck, Enolink,
Enomem, Enospc, Enosr, Enostr, Enosys, Enotblk, Enotdir, Enotsup, Enxio,
Eopnotsupp, Eoverflow, Eperm, Epipe, Erange, Erofs, Espipe, Esrch, Estale,
Etxtbsy, Exdev, Execute, File, FilePermissions, NotUtf8, Read, Unknown, Write,
append, append_bits, copy, copy_directory, copy_file, create_directory,
create_directory_all, create_file, create_link, create_symlink, delete,
delete_all, file_info, file_info_permissions, file_info_permissions_octal,
file_info_type, file_permissions_to_octal, get_files, is_directory, is_file,
is_symlink, link_info, read, read_bits, read_directory, rename,
set_permissions, set_permissions_octal, write, write_bits,
type FileError, Directory, Eacces, Eagain, Ebadf, Ebadmsg, Ebusy, Edeadlk,
Edeadlock, Edquot, Eexist, Efault, Efbig, Eftype, Einval, Eio, Eisdir, Eloop,
Emfile, Emlink, Emultihop, Enametoolong, Enfile, Enobufs, Enodev, Enoent,
Enolck, Enolink, Enomem, Enospc, Enosr, Enostr, Enosys, Enotblk, Enotdir,
Enotsup, Enxio, Eopnotsupp, Eoverflow, Eperm, Epipe, Erange, Erofs, Espipe,
Esrch, Estale, Etxtbsy, Exdev, Execute, File, FilePermissions, NotUtf8, Read,
Unknown, Write, append, append_bits, copy, copy_directory, copy_file,
create_directory, create_directory_all, create_file, create_link,
create_symlink, delete, delete_all, file_info, file_info_permissions,
file_info_permissions_octal, file_info_type, file_permissions_to_octal,
get_files, is_directory, is_file, is_symlink, link_info, read, read_bits,
read_directory, rename, set_permissions, set_permissions_octal, write,
write_bits,
}

pub fn main() {
Expand Down Expand Up @@ -483,7 +485,9 @@ pub fn file_info_get_permissions_test() {
pub fn get_files_with_slash_test() {
let assert Ok(files) = get_files(in: "./test/")
files
|> should.equal(["./test/simplifile_test.gleam"])
|> should.equal([
"./test/simplifile_test.gleam",
])
}

// This test is only for local development
Expand Down Expand Up @@ -761,3 +765,19 @@ pub fn parse_errors_test() {
simplifile.create_directory_all("./tmp/wumbo/wombo") |> should.be_error
err |> should.equal(Enotdir)
}

pub fn unknown_errors_return_unknown_test() {
let err = create_directory_with_bad_arg(#(Nil, Nil))
err |> should.be_error

let assert Error(unknown) = err
let assert Unknown(inner) = unknown
inner |> should.not_equal("")
inner |> string.uppercase |> should.equal(inner)
// confirm the string has been uppercased
}

// This is necessary to force unknown error generation uniformly across runtimes
@external(erlang, "simplifile_erl", "create_directory")
@external(javascript, "./simplifile_js.mjs", "createDirectory")
fn create_directory_with_bad_arg(arg: #(Nil, Nil)) -> Result(Nil, FileError)