TheAngryDarling / SwiftCodeStackTrace

A structure containing a manually callable stack trace

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code Stack Trace

macOS Linux Apache 2.0

A structure containing a manually callable stack trace. Storing File Path, Function, and Line number.

This object was mainly created for debugging, allowing developers to follow code calls within their own code.

Requirements

  • Xcode 9+ (If working within Xcode)
  • Swift 4.0+

Usage

enum CodeError: Error {
    case someError(trace: CodeStackTrace)
}

// Start the Stack Trace
let stackTrace = CodeStackTrace()

func someFunction(argument: Int, stack: CodeStackTrace) throws {
    ... do code here, pass stack.stacking() to any additional functions
    throw CodeError.someError(trace: stack)
}

do {
    try someFunction(argument: 0, stack: stackTrace.stacking())
} catch CodeError.someError(trace: let stackTrace) {
    print("Some Error:\n" + stackTrace.map( { return $0.description } ).joined(separator: "\n))
} catch {
    // some other error occured
} 

Author

  • Tyler Anger - Initial work

License

Copyright 2022 Tyler Anger

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

HERE or http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

A structure containing a manually callable stack trace

License:Apache License 2.0


Languages

Language:Swift 100.0%