Avoid unnecessary try catch in Typescript

Don't wrap large blocks of code in try/catch when you're only logging the error message without preserving the stack trace.
### Bad
```typescript
async function doSomething() {
  try {
    // Large block of code with multiple potential error sources
    await fetchData()

Install this rule for wispbit

Quick Install

Recommended
View install script

Run this one command to automatically install the rule:

curl -fsSL https://wispbit.com/api/install?rule=typescript-unnecessary-try-catch | bash

Manual install

1

Copy the rule

---
include: *.ts
---
Don't wrap large blocks of code in try/catch when you're only logging the error message without preserving the stack trace.
### Bad
```typescript
async function doSomething() {
  try {
    // Large block of code with multiple potential error sources
    await fetchData()
    await processData()
    await saveResults()
  } catch (error) {
    console.error(`Error: ${(error as Error).message}`)
    process.exit(1)
  }
}
```
### Good
```typescript
async function doSomething() {
  // Let errors propagate with their full stack trace
  // or handle specific errors at appropriate points
  await fetchData()
  await processData()
  await saveResults()
}
// If you need top-level error handling:
async function main() {
  try {
    await doSomething()
  } catch (error) {
    console.error("Unexpected error:", error)
    process.exit(1)
  }
}
```
2

Add the rule into your project

Save the copied content as: .wispbit/rules/typescript-unnecessary-try-catch.md

Install this rule for Coderabbit

Copy the configuration below and add it to your repository as .coderabbit.yml in your project root.

reviews:
  path_instructions:
    - path: "*.ts"
      instructions: |
                
        Don't wrap large blocks of code in try/catch when you're only logging the error message without preserving the stack trace.
        
        ### Bad
        
        ```typescript
        async function doSomething() {
          try {
            // Large block of code with multiple potential error sources
            await fetchData()
            await processData()
            await saveResults()
          } catch (error) {
            console.error(`Error: ${(error as Error).message}`)
            process.exit(1)
          }
        }
        ```
        
        ### Good
        
        ```typescript
        async function doSomething() {
          // Let errors propagate with their full stack trace
          // or handle specific errors at appropriate points
          await fetchData()
          await processData()
          await saveResults()
        }
        
        // If you need top-level error handling:
        async function main() {
          try {
            await doSomething()
          } catch (error) {
            console.error("Unexpected error:", error)
            process.exit(1)
          }
        }
        ```
        

Install this rule for Greptile

Greptile rules can be added through the web interface. Please see this documentation for details on how to add custom rules and context.

Don't wrap large blocks of code in try/catch when you're only logging the error message without preserving the stack trace.
### Bad
```typescript
async function doSomething() {
  try {
    // Large block of code with multiple potential error sources
    await fetchData()
    await processData()
    await saveResults()
  } catch (error) {
    console.error(`Error: ${(error as Error).message}`)
    process.exit(1)
  }
}
```
### Good
```typescript
async function doSomething() {
  // Let errors propagate with their full stack trace
  // or handle specific errors at appropriate points
  await fetchData()
  await processData()
  await saveResults()
}
// If you need top-level error handling:
async function main() {
  try {
    await doSomething()
  } catch (error) {
    console.error("Unexpected error:", error)
    process.exit(1)
  }
}
```

File Path Patterns:

*.ts

Install this rule for GitHub Copilot

Copilot instructions can be added through the interface. See the documentation for details on how to create coding guidelines.

Don't wrap large blocks of code in try/catch when you're only logging the error message without preserving the stack trace.
### Bad
```typescript
async function doSomething() {
  try {
    // Large block of code with multiple potential error sources
    await fetchData()
    await processData()
    await saveResults()
  } catch (error) {
    console.error(`Error: ${(error as Error).message}`)
    process.exit(1)
  }
}
```
### Good
```typescript
async function doSomething() {
  // Let errors propagate with their full stack trace
  // or handle specific errors at appropriate points
  await fetchData()
  await processData()
  await saveResults()
}
// If you need top-level error handling:
async function main() {
  try {
    await doSomething()
  } catch (error) {
    console.error("Unexpected error:", error)
    process.exit(1)
  }
}
```

File Path Patterns:

*.ts

Install this rule for Graphite Diamond

Diamond custom rules can be added through the interface. See the documentation for details on how to create custom rules.

Don't wrap large blocks of code in try/catch when you're only logging the error message without preserving the stack trace.
### Bad
```typescript
async function doSomething() {
  try {
    // Large block of code with multiple potential error sources
    await fetchData()
    await processData()
    await saveResults()
  } catch (error) {
    console.error(`Error: ${(error as Error).message}`)
    process.exit(1)
  }
}
```
### Good
```typescript
async function doSomething() {
  // Let errors propagate with their full stack trace
  // or handle specific errors at appropriate points
  await fetchData()
  await processData()
  await saveResults()
}
// If you need top-level error handling:
async function main() {
  try {
    await doSomething()
  } catch (error) {
    console.error("Unexpected error:", error)
    process.exit(1)
  }
}
```

File Path Patterns:

*.ts