Challenge - 5 Problems
Deno Error Handling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediateWhat is the output of this Deno error handling code?
Consider this Deno script that tries to read a file and logs errors. What will it output if the file does not exist?
Deno
try { const data = await Deno.readTextFile("nofile.txt"); console.log(data); } catch (error) { console.error("Error reading file:", error.message); }
Attempts:
2 left
💡 Hint
Think about what happens when you try to read a file that does not exist in Deno.
✗ Incorrect
When Deno.readTextFile tries to read a non-existent file, it throws an error. The catch block logs the error message, which includes 'No such file or directory'.
🧠 Conceptual
intermediateWhich Deno API is best for structured logging with levels?
You want to add logs with levels like info, warning, and error in a Deno application. Which built-in or standard module should you use?
Attempts:
2 left
💡 Hint
Look for a standard library module designed for logging with levels.
✗ Incorrect
Deno's std/log module provides structured logging with levels like info, warning, error, and supports handlers and formatters.
❓ Troubleshoot
advancedWhy does this Deno script fail to catch the error?
This Deno script tries to catch errors from an async function but fails. Why?
```typescript
async function readFile() {
Deno.readTextFile("nofile.txt");
}
try {
await readFile();
} catch (e) {
console.error("Caught error:", e.message);
}
```
Attempts:
2 left
💡 Hint
Check if the promise returned by Deno.readTextFile is awaited inside the async function.
✗ Incorrect
Without awaiting Deno.readTextFile, the error happens asynchronously and is not caught by the outer try-catch.
🔀 Workflow
advancedWhat is the correct order to set up logging with std/log in Deno?
Arrange these steps in the correct order to initialize and use the std/log module for logging in Deno.
Attempts:
2 left
💡 Hint
Think about importing first, then configuring, then initializing, then using.
✗ Incorrect
You must import the module first, then configure the logger, then call setup to initialize, and finally use the logging functions.
✅ Best Practice
expertWhich approach is best for error logging in a Deno production app?
You want to log errors in a Deno app running in production. Which approach is best to ensure errors are logged with context and can be monitored externally?
Attempts:
2 left
💡 Hint
Think about scalable, centralized logging for production environments.
✗ Incorrect
Using std/log with custom handlers allows sending structured logs to remote monitoring services, which is best practice for production.
