Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
2jammers committed Sep 2, 2024
1 parent 68ba3c1 commit 76e5936
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 25 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]

### Added

- Added a `Parse` function for use in xpcalls

## [0.2.0] - 2024-09-02

### Changed
Expand Down
7 changes: 7 additions & 0 deletions src/Types.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type ParsedError = {
Raw: string,
Message: string,
Trace: string,
}

return {}
37 changes: 29 additions & 8 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
local RunService = game:GetService("RunService")
local PackageLinksAllowed = RunService:IsStudio()

local Types = require(script.Types)

local LogList = nil
local Metadata = {
PackageURL = "",
PackageName = "Package",
TraceLevel = 3,
}

-- Functions
Expand Down Expand Up @@ -39,16 +42,16 @@ end
[Learn More](https://google.com)
]=]
local function Format(logId: string, ...: any): string
local function Format(logId: string, trace: string, ...: any): string
assert(LogList[logId], "Invalid log ID")
local Traceback = debug.traceback(nil, 3)
return string.gsub(
`[{Metadata.PackageName}] {LogList[logId] or "Package"}{if Metadata.PackageURL ~= ""
local FormattedLog = string.format(LogList[logId] or "Unknown", ...)
return (string.gsub(
`[{Metadata.PackageName}] {FormattedLog}{if Metadata.PackageURL ~= ""
then `\nLearn: {Metadata.PackageURL}`
else ""}\nTrace: {Traceback}`,
else ""}\nTrace: {(string.gsub(trace, "\n", ""))}`,
"\n",
"\n\t\t\t\t"
)
))
end

--[=[
Expand All @@ -57,7 +60,7 @@ end
[Learn More](https://google.com)
]=]
local function Fatal(logId: string, ...: any): never
error(Format(logId, ...), 0)
error(Format(logId, debug.traceback(nil, Metadata.TraceLevel), ...), 0)
end

--[=[
Expand All @@ -66,7 +69,7 @@ end
[Learn More](https://google.com)
]=]
local function Warn(logId: string, ...: any)
warn(Format(logId, ...))
warn(Format(logId, debug.traceback(nil, Metadata.TraceLevel), ...))
end

--[=[
Expand All @@ -81,6 +84,23 @@ local function Assert<T>(condition: T, logId: string, ...: any): T
return Fatal(logId, ...)
end

--[=[
Extracts info from xpcall errors to beautify it.
[Learn More](https://google.com)
]=]
local function Parse(error: string): Types.ParsedError
return {
Raw = error,
Message = string.gsub(error, "^.+:%d+:%s*", ""),
Trace = debug.traceback(nil, Metadata.TraceLevel),
}
end

-- Types

export type ParsedError = Types.ParsedError

-- Module

return table.freeze({
Expand All @@ -90,4 +110,5 @@ return table.freeze({
Fatal = Fatal,
Warn = Warn,
Assert = Assert,
Parse = Parse,
})
14 changes: 0 additions & 14 deletions tests/client/hello.luau

This file was deleted.

26 changes: 24 additions & 2 deletions tests/client/test.client.luau
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
local hi = require(script.Parent.hello)
hi()
local Debugger = require(game.ReplicatedStorage.Packages.debugger)
local TestModule = require(script.Parent.testmodule)

Debugger.SetMetadata({
PackageURL = "https://lumin-dev.github.io/LuminFramework/",
PackageName = "Lumin Framework",
TraceLevel = 2,
})

Debugger.SetLogs({
Good = "hi can you please say hi",
Bad = "OH NO - %s",
})

Debugger.Warn("Good")

local result, message = xpcall(function()
TestModule()
end, Debugger.Parse)

if not result then
local error_message = message :: Debugger.ParsedError
Debugger.Warn("Bad", error_message.Message)
end
3 changes: 3 additions & 0 deletions tests/client/testmodule.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return function()
print(workspace.DoesNotExist)
end
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "lumin/debugger"
description = "A customizable and extendable debugger for open source software."
version = "0.2.0"
version = "0.3.0"
license = "MIT"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
Expand Down

0 comments on commit 76e5936

Please sign in to comment.