Skip to content

Commit 7cec3cb

Browse files
committed
add inner string to unknown
1 parent 22ae565 commit 7cec3cb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Add underlying string as context to `Unknown` error
56
- improve performance of `get_files`
67

78
## v1.7.0 - 5 April 2024

src/simplifile.gleam

+8-6
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub type FileError {
113113
/// File was requested to be read as UTF-8, but is not UTF-8 encoded.
114114
NotUtf8
115115
/// Any error not accounted for by this type
116-
Unknown
116+
Unknown(inner: String)
117117
}
118118

119119
/// Convert an error into a human-readable description
@@ -172,7 +172,7 @@ pub fn describe_error(error: FileError) -> String {
172172
Enostr -> "Not a STREAM"
173173
Eopnotsupp -> "Operation not supported on socket"
174174
NotUtf8 -> "File not UTF-8 encoded"
175-
Unknown -> "Unknown error"
175+
Unknown(inner) -> "Unknown error: " <> inner
176176
}
177177
}
178178

@@ -529,12 +529,14 @@ fn do_copy_directory(src: String, dest: String) -> Result(Nil, FileError) {
529529
use _ <- result.try(create_directory(dest_path))
530530
do_copy_directory(src_path, dest_path)
531531
}
532-
Error(e), _ | _, Error(e) -> {
532+
Error(e), _
533+
| _, Error(e) -> {
533534
Error(e)
534535
}
535-
Ok(False), Ok(False) | Ok(True), Ok(True) -> {
536+
Ok(False), Ok(False)
537+
| Ok(True), Ok(True) -> {
536538
// We're really not sure how that one happened.
537-
Error(Unknown)
539+
Error(Unknown("Unknown error copying directory"))
538540
}
539541
}
540542
})
@@ -808,7 +810,7 @@ fn cast_error(input: Result(a, String)) -> Result(a, FileError) {
808810
"ETXTBSY" -> Etxtbsy
809811
"EXDEV" -> Exdev
810812
"NOTUTF8" -> NotUtf8
811-
_ -> Unknown
813+
str -> Unknown(str)
812814
}
813815
})
814816
}

0 commit comments

Comments
 (0)