diff --git a/CHANGELOG.md b/CHANGELOG.md index e3fc3ec..1b0cbd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - yyyy-mm-dd +## [0.1.9] - 2024-09-13 + +- Fix usage of abort instead of panic. + ## [0.1.8] - 2024-09-13 - Lot's of changes since Mojo 24.5. Sorry, I don't have a more granualar changelog! diff --git a/mojoproject.toml b/mojoproject.toml index 467afc6..548279d 100644 --- a/mojoproject.toml +++ b/mojoproject.toml @@ -4,7 +4,7 @@ channels = ["conda-forge", "https://conda.modular.com/max"] description = "Experiments in porting over Golang stdlib into Mojo." name = "gojo" platforms = ["osx-arm64", "linux-64"] -version = "0.1.8" +version = "0.1.9" [tasks] tests = "bash scripts/tests.sh" diff --git a/src/gojo/__init__.mojo b/src/gojo/__init__.mojo index e69de29..0001ae7 100644 --- a/src/gojo/__init__.mojo +++ b/src/gojo/__init__.mojo @@ -0,0 +1,12 @@ +from sys import exit + + +fn panic[T: Stringable](message: T, code: Int = 1): + """Panics the program with the given message and exit code. + + Args: + message: The message to panic with. + code: The exit code to panic with. + """ + print("panic:", str(message)) + exit(code) diff --git a/src/gojo/bufio/reader.mojo b/src/gojo/bufio/reader.mojo index 5345db0..08c195e 100644 --- a/src/gojo/bufio/reader.mojo +++ b/src/gojo/bufio/reader.mojo @@ -142,7 +142,7 @@ struct Reader[R: io.Reader, //](Sized, io.Reader, io.ByteReader, io.ByteScanner, # Compares to the capacity of the internal buffer. # IE. var b = List[UInt8, True](capacity=4096), then trying to write at b[4096] and onwards will fail. if self.write_pos >= self.buf.capacity: - abort("bufio.Reader: tried to fill full buffer") + panic("bufio.Reader: tried to fill full buffer") # Read new data: try a limited number of times. var i: Int = MAX_CONSECUTIVE_EMPTY_READS @@ -152,7 +152,7 @@ struct Reader[R: io.Reader, //](Sized, io.Reader, io.ByteReader, io.ByteScanner, var err: Error bytes_read, err = self.reader._read(dest_ptr, self.buf.capacity - self.buf.size) if bytes_read < 0: - abort(ERR_NEGATIVE_READ) + panic(ERR_NEGATIVE_READ) self.buf.size += bytes_read self.write_pos += bytes_read @@ -283,7 +283,7 @@ struct Reader[R: io.Reader, //](Sized, io.Reader, io.ByteReader, io.ByteScanner, bytes_read, self.err = self.reader._read(dest, capacity) if bytes_read < 0: - abort(ERR_NEGATIVE_READ) + panic(ERR_NEGATIVE_READ) if bytes_read > 0: self.last_byte = int(dest[bytes_read - 1]) @@ -300,7 +300,7 @@ struct Reader[R: io.Reader, //](Sized, io.Reader, io.ByteReader, io.ByteScanner, bytes_read, self.err = self.reader._read(buf, self.buf.capacity - self.buf.size) if bytes_read < 0: - abort(ERR_NEGATIVE_READ) + panic(ERR_NEGATIVE_READ) if bytes_read == 0: return 0, self.read_error() @@ -498,7 +498,7 @@ struct Reader[R: io.Reader, //](Sized, io.Reader, io.ByteReader, io.ByteScanner, # Let the next call to read_line check for "\r\n". if self.read_pos == 0: # should be unreachable - abort("bufio: tried to rewind past start of buffer") + panic("bufio: tried to rewind past start of buffer") self.read_pos -= 1 line = line[: len(line) - 1] @@ -672,7 +672,7 @@ struct Reader[R: io.Reader, //](Sized, io.Reader, io.ByteReader, io.ByteScanner, return bytes_written, err if bytes_written < 0: - abort(ERR_NEGATIVE_WRITE) + panic(ERR_NEGATIVE_WRITE) self.read_pos += bytes_written return Int(bytes_written), Error() diff --git a/src/gojo/bufio/scan.mojo b/src/gojo/bufio/scan.mojo index 54325de..77e3116 100644 --- a/src/gojo/bufio/scan.mojo +++ b/src/gojo/bufio/scan.mojo @@ -166,7 +166,7 @@ struct Scanner[R: io.Reader, //, split: SplitFunction = scan_lines](): # Returning tokens not advancing input at EOF. self.empties += 1 if self.empties > MAX_CONSECUTIVE_EMPTY_READS: - abort("bufio.Scan: too many empty tokens without progressing") + panic("bufio.Scan: too many empty tokens without progressing") return True diff --git a/src/gojo/bytes/buffer.mojo b/src/gojo/bytes/buffer.mojo index ae5dfe1..49fa276 100644 --- a/src/gojo/bytes/buffer.mojo +++ b/src/gojo/bytes/buffer.mojo @@ -482,7 +482,7 @@ struct Buffer( var err: Error bytes_written, err = writer.write(self.as_bytes_slice()[self.offset :]) if bytes_written > bytes_to_write: - abort("bytes.Buffer.write_to: invalid write count") + panic("bytes.Buffer.write_to: invalid write count") self.offset += bytes_written total_bytes_written = bytes_written diff --git a/src/gojo/bytes/reader.mojo b/src/gojo/bytes/reader.mojo index 6a9dd0a..7f9f823 100644 --- a/src/gojo/bytes/reader.mojo +++ b/src/gojo/bytes/reader.mojo @@ -273,7 +273,7 @@ struct Reader( var err: Error write_count, err = writer.write(bytes) if write_count > len(bytes): - abort("bytes.Reader.write_to: invalid Write count") + panic("bytes.Reader.write_to: invalid Write count") self.index += write_count if write_count != len(bytes): diff --git a/src/gojo/strings/reader.mojo b/src/gojo/strings/reader.mojo index 70c38b5..a0675ba 100644 --- a/src/gojo/strings/reader.mojo +++ b/src/gojo/strings/reader.mojo @@ -233,7 +233,7 @@ struct Reader( var bytes_written: Int bytes_written, err = writer.write(chunk_to_write) if bytes_written > len(chunk_to_write): - abort("strings.Reader.write_to: invalid write_string count") + panic("strings.Reader.write_to: invalid write_string count") self.read_pos += bytes_written if bytes_written != len(chunk_to_write) and not err: diff --git a/src/recipe.yaml b/src/recipe.yaml index 2b6ff2f..b8ee568 100644 --- a/src/recipe.yaml +++ b/src/recipe.yaml @@ -5,7 +5,7 @@ context: package: name: "gojo" - version: 0.1.8 + version: 0.1.9 source: - path: .