# Deno

## 👀 Getting Started

Adding BugSplat error reporting to your [Deno](https://deno.com/) application, web worker, or serverless function only takes a few lines of code. Once integrated, BugSplat will capture stack traces, logs, and other valuable insight when your code encounters a problem. BugSplat's [bugsplat-js](https://github.com/BugSplat-Git/bugsplat-js) package is fully typed and easily imported via [esm.sh](https://esm.sh/).

## ⚙️ Integrating

Add an import from [bugsplat-js](https://github.com/BugSplat-Git/bugsplat-js) via [esm.sh](https://esm.sh/):

```typescript
import { BugSplat } from 'https://esm.sh/bugsplat@8.0.1';
```

Create a new instance of the `BugSplat` class with the name of your BugSplat database, the name of your application, and the version of your application:

```typescript
const bugsplat = new BugSplat('DatabaseName', 'AppName', '1.0.0');
```

Use the `bugsplat` instance to capture errors that originate inside of try-catch blocks:

```typescript
try {
  throw new Error("BugSplat");
} catch (error) {
  await bugsplat.post(error);
}
```

Use `bugsplat` to post errors from promise rejections:

```typescript
Promise.reject(new Error("BugSplat!")).catch(error => bugsplat.post(error, {}));
```

You can also attach a file to your error post by passing a `BugSplatOptions` object containing with a value for `additionalFormDataParams` property.

```typescript
await bugsplat.post(error, getAdditionalOptionsWithLogFile());

function getAdditionalOptionsWithLogFile() {
  const filename = 'log.txt';
  return {
    additionalFormDataParams: [{
      key: 'file',
      value: new File([Deno.readFileSync(filename)], filename),
      filename: filename,
    }],
  };
}
```

## 🧪 Sample

Clone the [my-deno-crasher](https://github.com/BugSplat-Git/my-deno-crasher) repository:

```bash
git clone https://github.com/BugSplat-Git/my-deno-crasher
```

Set your current directory to `my-deno-crasher`.

```bash
cd my-deno-crasher
```

Run the sample with the `--allow-net` and `--allow-read` flags to allow BugSplat to post an error to our backend and read the log file respectively.

```bash
deno run --allow-net --allow-read main.ts
```

## 📈 Viewing Reports

After posting an error, navigate to the [Crashes](https://app.bugsplat.com/v2/crashes) page. You should see a new crash report for the application you just configured. Click the link in the ID column to see details about your crash on the [Crashes](https://app.bugsplat.com/v2/crashes) page:

<figure><img src="https://976110677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LBMgmIcgkIXSUfnXDSv%2Fuploads%2Fihf4moKSIhncTG8KX1vi%2Fimage.png?alt=media&#x26;token=edbc1ec2-1827-44ab-bcc5-b53c605c6880" alt=""><figcaption><p>Deno Error Reports</p></figcaption></figure>

<figure><img src="https://976110677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LBMgmIcgkIXSUfnXDSv%2Fuploads%2FFvIGfx5e15CvHHk05zhm%2Fimage.png?alt=media&#x26;token=f4fec7be-308e-4b58-a97b-3f00db7b8c40" alt=""><figcaption><p>Deno Error Report</p></figcaption></figure>

That’s it! Your application is now configured to post error reports to BugSplat.

## 🧩 API

In addition to the configuration demonstrated above, there are a few public methods that can be used to customize your BugSplat integration:

```typescript
bugsplat.setDefaultAppKey(appKey); // Additional metadata that can be queried via BugSplats web application
bugsplat.setDefaultUser(user); // The name or id of your user
bugsplat.setDefaultEmail(email); // The email of your user
bugsplat.setDefaultDescription(description); // Additional info about your crash that gets reset after every post
async bugsplat.post(error, options); // Posts an arbitrary Error object to BugSplat
// If the values options.appKey, options.user, options.email, options.description are set the corresponding default values will be overwritten
// Returns a promise that resolves with properties: error (if there was an error posting to BugSplat), response (the response from the BugSplat crash post API), and original (the error passed by bugsplat.post)
```

## 🤝 Contributing

BugSplat loves open-source software! Please check out our project on [GitHub](https://github.com/BugSplat-Git/bugsplat-js) and send us a Pull Request.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bugsplat.com/introduction/getting-started/integrations/cross-platform/deno.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
