Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Command-Line Failure to Upload #1522

Open
shepting opened this issue Feb 15, 2023 · 3 comments
Open

Swift Command-Line Failure to Upload #1522

shepting opened this issue Feb 15, 2023 · 3 comments
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature

Comments

@shepting
Copy link

shepting commented Feb 15, 2023

Describe the bug

I can follow the instructions for setting up the Bugsnag SDK, but when running inside a Swift command-line app the crashes never make it to Bugsnag. The crash report gets written out, but it doesn't show up in the web UI.

Build logs
Screenshot 2023-02-14 at 7 16 01 PM

Steps to reproduce

  1. Type swift run
  2. See that no events show up in the Bugsnag Web UI

Environment

  • Bugsnag version: 6.6.1
  • iOS/tvOS/macOS version(s): Ventura 13.2
  • Xcode version: 14.2
  • Swift version (if applicable): 5.7

Example code snippet

Setup

Sources/Porter.swift

import Foundation
import Bugsnag

@main
public struct Porter {

    public static func main() {
      log("Hello, \u{1F30E}!")

      // API key for Bugsnag Swift tooling
      Bugsnag.start(withApiKey: "9be<redacted>")

      Bugsnag.notifyError(NSError(domain:"com.porter.mac.test_error", code:422, userInfo:nil))
      print("Done")
    }
}

Package.swift

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Porter",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
      .package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", .upToNextMajor(from: "4.0.0")),
      .package(url: "https://github.com/bugsnag/bugsnag-cocoa", .upToNextMajor(from: "6.0.0")),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .executableTarget(
            name: "Porter",
            dependencies: ["SwiftyJSON", .product(name: "Bugsnag", package: "bugsnag-cocoa")],
            path: "Sources"),
        .testTarget(
            name: "PorterTests",
            dependencies: ["Porter"],
            path: "Tests"),
    ]
)
Log output when running from Xcode
[0;34mHello, 🌎!�[0;0m
2023-02-15 09:03:56.108605-0800 Porter[94166:13134073] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=94166
2023-02-15 09:03:56.108798-0800 Porter[94166:13134073] SecTaskCopyDebugDescription: Porter[94166]/0#-1 LF=0
2023-02-15 09:03:56.129630-0800 Porter[94166:13134073] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=94166
2023-02-15 09:03:56.129747-0800 Porter[94166:13134073] SecTaskCopyDebugDescription: Porter[94166]/0#-1 LF=0
WARN : BSG_KSCrashSentry.c (104): BSG_KSCrashType bsg_kscrashsentry_installWithContext(BSG_KSCrash_SentryContext *, BSG_KSCrashType, void (*)(void *)): App is running in a debugger. Only handled events will be sent to Bugsnag.
WARN : BSG_KSCrashSentry.c (104): BSG_KSCrashType bsg_kscrashsentry_installWithContext(BSG_KSCrash_SentryContext *, BSG_KSCrashType, void (*)(void *)): App is running in a debugger. Only handled events will be sent to Bugsnag.
ERROR: BSG_KSMach.c (201): _Bool bsg_ksmachfillState(const thread_t, const thread_state_t, const thread_state_flavor_t, const mach_msg_type_number_t): thread_get_state: (ipc/send) invalid destination port
ERROR: BSG_KSCrashReport.c (397): struct __darwin_mcontext64 *bsg_kscrw_i_getMachineContext(const BSG_KSCrash_SentryContext *const, const thread_t, struct __darwin_mcontext64 *const): Failed to fetch machine state for thread 2819
ERROR: BSG_KSMach.c (201): _Bool bsg_ksmachfillState(const thread_t, const thread_state_t, const thread_state_flavor_t, const mach_msg_type_number_t): thread_get_state: (ipc/send) invalid destination port
ERROR: BSG_KSCrashReport.c (397): struct __darwin_mcontext64 *bsg_kscrw_i_getMachineContext(const BSG_KSCrash_SentryContext *const, const thread_t, struct __darwin_mcontext64 *const): Failed to fetch machine state for thread 3331
ERROR: BSG_KSMach.c (201): _Bool bsg_ksmachfillState(const thread_t, const thread_state_t, const thread_state_flavor_t, const mach_msg_type_number_t): thread_get_state: (os/kern) invalid argument
ERROR: BSG_KSCrashReport.c (397): struct __darwin_mcontext64 *bsg_kscrw_i_getMachineContext(const BSG_KSCrash_SentryContext *const, const thread_t, struct __darwin_mcontext64 *const): Failed to fetch machine state for thread 28679
INFO : BSG_KSCrashReport.c (1564): void bsg_kscrashreport_writeStandardReport(BSG_KSCrash_Context *const, const char *const): Writing crash report to /Users/stevenhepting/Library/Application Support/com.bugsnag.Bugsnag/(null)/v1/KSCrashReports/(null)-CrashReport-D975108A-68D3-4CA7-83CF-14548C4727DF.json
Done
Program ended with exit code: 0
Log output when running from the command-line with SPM (`swift run`)
╰─ swift run
Building for debugging...
[3/3] Linking Porter
Build complete! (0.75s)
Hello, 🌎!
INFO : BSG_KSCrashReport.c (1564): void bsg_kscrashreport_writeStandardReport(BSG_KSCrash_Context *const, const char *const): Writing crash report to /Users/stevenhepting/Library/Application Support/com.bugsnag.Bugsnag/(null)/v1/KSCrashReports/(null)-CrashReport-0D3B2D79-DC4D-4B91-B184-3702289E71A9.json
Done
@shepting
Copy link
Author

@kstenerud Not sure if I'm just configuring this wrong, but ideally there would be some type of error messages explaining the failure to upload.

@shepting
Copy link
Author

The interesting thing, is that I can add this same key to a new test app that runs in the iOS Simulator and it works fine. My two test events uploaded without error:
Screenshot 2023-02-15 at 9 38 24 AM

@luke-belton
Copy link
Member

Hi @shepting - bugsnag-cocoa doesn't currently support native Swift apps, including Swift CLI apps. We have an item on our product roadmap to support this in the future, however I don't have an ETA for that at this stage. We'll make sure that we keep this thread updated 👍

@luke-belton luke-belton added feature request Request for a new feature backlog We hope to fix this feature/bug in the future labels Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants