Reputation: 9072
In the following Deno test snippet:
await assertRejects(
async (): Promise<void> => {
for await (const entry of walk('./non-existent-directory')) {
console.log(entry)
}
},
NotFound,
'No such file or directory'
)
Deno spells out the type and message to the console NotFound: No such file or directory (os error 2)
but where is that NotFound
exception declared? When I run the snipped as is using Deno's standard testing library , I get error: TS2304 [ERROR]: Cannot find name 'NotFound'.
Upvotes: 2
Views: 336
Reputation: 40414
Deno specific errors can be accessed through Deno.errors
.
For NotFound
you should use:
await assertThrowsAsync(
async (): Promise<void> => {
for await (const entry of walk('./non-existent-directory')) {
console.log(entry)
}
},
Deno.errors.NotFound,
'No such file or directory'
)
Here's the full list:
Deno.errors.AddrInUse
Deno.errors.AddrNotAvailable
Deno.errors.AlreadyExists
Deno.errors.BadResource
Deno.errors.BrokenPipe
Deno.errors.Busy
Deno.errors.ConnectionAborted
Deno.errors.ConnectionRefused
Deno.errors.ConnectionReset
Deno.errors.FilesystemLoop
Deno.errors.Http
Deno.errors.Interrupted
Deno.errors.InvalidData
Deno.errors.IsADirectory
Deno.errors.NetworkUnreachable
Deno.errors.NotADirectory
Deno.errors.NotConnected
Deno.errors.NotFound
Deno.errors.NotSupported
Deno.errors.PermissionDenied
Deno.errors.TimedOut
Deno.errors.UnexpectedEof
Deno.errors.WouldBlock
Deno.errors.WriteZero
Upvotes: 2