Skip to content

Commit

Permalink
fix assert
Browse files Browse the repository at this point in the history
  • Loading branch information
jmesrje committed Sep 21, 2024
1 parent bc29323 commit d6b645a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fixed incorrect behavior with `Assert`

## [0.3.0] - 2024-09-02

### Added
Expand Down
20 changes: 10 additions & 10 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local Metadata = {
--[=[
Sets specific metadata for formatting; such as a custom web link or package name.
[Learn More](https://google.com)
[Learn More](https://luminlabsdev.github.io/debugger/api/#setmetadata)
]=]
local function SetMetadata(metadata: { [string]: any })
for key, value in metadata do
Expand All @@ -31,7 +31,7 @@ end
--[=[
Sets a list of logs to be referenced within formatters.
[Learn More](https://google.com)
[Learn More](https://luminlabsdev.github.io/debugger/api/#setlogs)
]=]
local function SetLogs(logList: { [string]: string })
LogList = logList
Expand All @@ -40,7 +40,7 @@ end
--[=[
Base formatter for all debug functions, returns a formatted string with extra info.
[Learn More](https://google.com)
[Learn More](https://luminlabsdev.github.io/debugger/api/#format)
]=]
local function Format(logId: string, trace: string, ...: any): string
assert(LogList[logId], "Invalid log ID")
Expand All @@ -57,7 +57,7 @@ end
--[=[
Formats a fatal error of a log ID with provided parameters.
[Learn More](https://google.com)
[Learn More](https://luminlabsdev.github.io/debugger/api/#fatal)
]=]
local function Fatal(logId: string, ...: any): never
error(Format(logId, debug.traceback(nil, Metadata.TraceLevel), ...), 0)
Expand All @@ -66,28 +66,28 @@ end
--[=[
Formats a warning of a log ID with provided parameters.
[Learn More](https://google.com)
[Learn More](https://luminlabsdev.github.io/debugger/api/#warn)
]=]
local function Warn(logId: string, ...: any)
warn(Format(logId, debug.traceback(nil, Metadata.TraceLevel), ...))
end

--[=[
Returns the provided condition if it is false, behaves as the regular assert.
Returns the provided condition if it is true, behaves as the regular assert.
[Learn More](https://google.com)
[Learn More](https://luminlabsdev.github.io/debugger/api/#assert)
]=]
local function Assert<T>(condition: T, logId: string, ...: any): T
if not condition then
return condition :: any
return Fatal(logId, ...)
end
return Fatal(logId, ...)
return condition
end

--[=[
Extracts info from xpcall errors to beautify it.
[Learn More](https://google.com)
[Learn More](https://luminlabsdev.github.io/debugger/api/#parse)
]=]
local function Parse(error: string): Types.ParsedError
return {
Expand Down

0 comments on commit d6b645a

Please sign in to comment.