From d6b645a5618e2a1ffe7f8cfc89faff0bd5244d30 Mon Sep 17 00:00:00 2001 From: James <119134081+2jammers@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:16:40 -0500 Subject: [PATCH] fix assert --- docs/changelog.md | 4 ++++ src/init.luau | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 6a9ef85..3323339 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/src/init.luau b/src/init.luau index ccad4ec..2bbc7ec 100644 --- a/src/init.luau +++ b/src/init.luau @@ -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 @@ -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 @@ -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") @@ -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) @@ -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(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 {