mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
refactor: remove unneeded ErrorKinds (#3936)
This commit is contained in:
parent
d9efb8c02a
commit
dd8a109481
66 changed files with 553 additions and 620 deletions
|
@ -1,8 +1,34 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
use crate::diagnostics::Diagnostic;
|
|
||||||
use crate::fmt_errors::JSError;
|
//! This module implements error serialization; it
|
||||||
|
//! allows to serialize Rust errors to be sent to JS runtime.
|
||||||
|
//!
|
||||||
|
//! Currently it is deeply intertwined with `ErrBox` which is
|
||||||
|
//! not optimal since not every ErrBox can be "JS runtime error";
|
||||||
|
//! eg. there's no way to throw JSError/Diagnostic from within JS runtime
|
||||||
|
//!
|
||||||
|
//! There are many types of errors in Deno:
|
||||||
|
//! - ErrBox: a generic boxed object. This is the super type of all
|
||||||
|
//! errors handled in Rust.
|
||||||
|
//! - JSError: exceptions thrown from V8 into Rust. Usually a user exception.
|
||||||
|
//! These are basically a big JSON structure which holds information about
|
||||||
|
//! line numbers. We use this to pretty-print stack traces. These are
|
||||||
|
//! never passed back into the runtime.
|
||||||
|
//! - DenoError: these are errors that happen during ops, which are passed
|
||||||
|
//! back into the runtime, where an exception object is created and thrown.
|
||||||
|
//! DenoErrors have an integer code associated with them - access this via the kind() method.
|
||||||
|
//! - Diagnostic: these are errors that originate in TypeScript's compiler.
|
||||||
|
//! They're similar to JSError, in that they have line numbers.
|
||||||
|
//! But Diagnostics are compile-time type errors, whereas JSErrors are runtime exceptions.
|
||||||
|
//!
|
||||||
|
//! TODO:
|
||||||
|
//! - rename DenoError to OpError?
|
||||||
|
//! - rename JSError to RuntimeException. merge V8Exception?
|
||||||
|
//! - rename ErrorKind::Other. This corresponds to a generic exception thrown as the
|
||||||
|
//! global `Error` in JS:
|
||||||
|
//! https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
use crate::import_map::ImportMapError;
|
use crate::import_map::ImportMapError;
|
||||||
pub use crate::msg::ErrorKind;
|
|
||||||
use deno_core::AnyError;
|
use deno_core::AnyError;
|
||||||
use deno_core::ErrBox;
|
use deno_core::ErrBox;
|
||||||
use deno_core::ModuleResolutionError;
|
use deno_core::ModuleResolutionError;
|
||||||
|
@ -16,6 +42,34 @@ use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
use url;
|
use url;
|
||||||
|
|
||||||
|
// Warning! The values in this enum are duplicated in js/errors.ts
|
||||||
|
// Update carefully!
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#[repr(i8)]
|
||||||
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||||
|
pub enum ErrorKind {
|
||||||
|
NotFound = 1,
|
||||||
|
PermissionDenied = 2,
|
||||||
|
ConnectionRefused = 3,
|
||||||
|
ConnectionReset = 4,
|
||||||
|
ConnectionAborted = 5,
|
||||||
|
NotConnected = 6,
|
||||||
|
AddrInUse = 7,
|
||||||
|
AddrNotAvailable = 8,
|
||||||
|
BrokenPipe = 9,
|
||||||
|
AlreadyExists = 10,
|
||||||
|
InvalidData = 13,
|
||||||
|
TimedOut = 14,
|
||||||
|
Interrupted = 15,
|
||||||
|
WriteZero = 16,
|
||||||
|
UnexpectedEof = 17,
|
||||||
|
BadResource = 18,
|
||||||
|
Http = 19,
|
||||||
|
URIError = 20,
|
||||||
|
TypeError = 21,
|
||||||
|
Other = 22,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DenoError {
|
pub struct DenoError {
|
||||||
kind: ErrorKind,
|
kind: ErrorKind,
|
||||||
|
@ -76,11 +130,11 @@ pub fn permission_denied_msg(msg: String) -> ErrBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn no_buffer_specified() -> ErrBox {
|
pub fn no_buffer_specified() -> ErrBox {
|
||||||
StaticError(ErrorKind::InvalidInput, "no buffer specified").into()
|
StaticError(ErrorKind::TypeError, "no buffer specified").into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invalid_address_syntax() -> ErrBox {
|
pub fn invalid_address_syntax() -> ErrBox {
|
||||||
StaticError(ErrorKind::InvalidInput, "invalid address syntax").into()
|
StaticError(ErrorKind::TypeError, "invalid address syntax").into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn other_error(msg: String) -> ErrBox {
|
pub fn other_error(msg: String) -> ErrBox {
|
||||||
|
@ -103,18 +157,6 @@ impl GetErrorKind for StaticError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetErrorKind for JSError {
|
|
||||||
fn kind(&self) -> ErrorKind {
|
|
||||||
ErrorKind::JSError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetErrorKind for Diagnostic {
|
|
||||||
fn kind(&self) -> ErrorKind {
|
|
||||||
ErrorKind::Diagnostic
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetErrorKind for ImportMapError {
|
impl GetErrorKind for ImportMapError {
|
||||||
fn kind(&self) -> ErrorKind {
|
fn kind(&self) -> ErrorKind {
|
||||||
ErrorKind::Other
|
ErrorKind::Other
|
||||||
|
@ -123,12 +165,7 @@ impl GetErrorKind for ImportMapError {
|
||||||
|
|
||||||
impl GetErrorKind for ModuleResolutionError {
|
impl GetErrorKind for ModuleResolutionError {
|
||||||
fn kind(&self) -> ErrorKind {
|
fn kind(&self) -> ErrorKind {
|
||||||
use ModuleResolutionError::*;
|
ErrorKind::URIError
|
||||||
match self {
|
|
||||||
InvalidUrl(ref err) | InvalidBaseUrl(ref err) => err.kind(),
|
|
||||||
InvalidPath(_) => ErrorKind::InvalidPath,
|
|
||||||
ImportPrefixMissing(_, _) => ErrorKind::ImportPrefixMissing,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,13 +193,13 @@ impl GetErrorKind for io::Error {
|
||||||
AddrNotAvailable => ErrorKind::AddrNotAvailable,
|
AddrNotAvailable => ErrorKind::AddrNotAvailable,
|
||||||
BrokenPipe => ErrorKind::BrokenPipe,
|
BrokenPipe => ErrorKind::BrokenPipe,
|
||||||
AlreadyExists => ErrorKind::AlreadyExists,
|
AlreadyExists => ErrorKind::AlreadyExists,
|
||||||
WouldBlock => ErrorKind::WouldBlock,
|
InvalidInput => ErrorKind::TypeError,
|
||||||
InvalidInput => ErrorKind::InvalidInput,
|
|
||||||
InvalidData => ErrorKind::InvalidData,
|
InvalidData => ErrorKind::InvalidData,
|
||||||
TimedOut => ErrorKind::TimedOut,
|
TimedOut => ErrorKind::TimedOut,
|
||||||
Interrupted => ErrorKind::Interrupted,
|
Interrupted => ErrorKind::Interrupted,
|
||||||
WriteZero => ErrorKind::WriteZero,
|
WriteZero => ErrorKind::WriteZero,
|
||||||
UnexpectedEof => ErrorKind::UnexpectedEof,
|
UnexpectedEof => ErrorKind::UnexpectedEof,
|
||||||
|
WouldBlock => unreachable!(),
|
||||||
_ => ErrorKind::Other,
|
_ => ErrorKind::Other,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +207,7 @@ impl GetErrorKind for io::Error {
|
||||||
|
|
||||||
impl GetErrorKind for url::ParseError {
|
impl GetErrorKind for url::ParseError {
|
||||||
fn kind(&self) -> ErrorKind {
|
fn kind(&self) -> ErrorKind {
|
||||||
ErrorKind::UrlParse
|
ErrorKind::URIError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,8 +248,8 @@ impl GetErrorKind for serde_json::error::Error {
|
||||||
fn kind(&self) -> ErrorKind {
|
fn kind(&self) -> ErrorKind {
|
||||||
use serde_json::error::*;
|
use serde_json::error::*;
|
||||||
match self.classify() {
|
match self.classify() {
|
||||||
Category::Io => ErrorKind::InvalidInput,
|
Category::Io => ErrorKind::TypeError,
|
||||||
Category::Syntax => ErrorKind::InvalidInput,
|
Category::Syntax => ErrorKind::TypeError,
|
||||||
Category::Data => ErrorKind::InvalidData,
|
Category::Data => ErrorKind::InvalidData,
|
||||||
Category::Eof => ErrorKind::UnexpectedEof,
|
Category::Eof => ErrorKind::UnexpectedEof,
|
||||||
}
|
}
|
||||||
|
@ -230,10 +267,13 @@ mod unix {
|
||||||
fn kind(&self) -> ErrorKind {
|
fn kind(&self) -> ErrorKind {
|
||||||
match self {
|
match self {
|
||||||
Sys(EPERM) => ErrorKind::PermissionDenied,
|
Sys(EPERM) => ErrorKind::PermissionDenied,
|
||||||
Sys(EINVAL) => ErrorKind::InvalidInput,
|
Sys(EINVAL) => ErrorKind::TypeError,
|
||||||
Sys(ENOENT) => ErrorKind::NotFound,
|
Sys(ENOENT) => ErrorKind::NotFound,
|
||||||
Sys(_) => ErrorKind::UnixError,
|
Sys(UnknownErrno) => unreachable!(),
|
||||||
_ => ErrorKind::Other,
|
Sys(_) => unreachable!(),
|
||||||
|
Error::InvalidPath => ErrorKind::TypeError,
|
||||||
|
Error::InvalidUtf8 => ErrorKind::InvalidData,
|
||||||
|
Error::UnsupportedOperation => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,11 +308,9 @@ impl GetErrorKind for dyn AnyError {
|
||||||
|
|
||||||
None
|
None
|
||||||
.or_else(|| self.downcast_ref::<DenoError>().map(Get::kind))
|
.or_else(|| self.downcast_ref::<DenoError>().map(Get::kind))
|
||||||
.or_else(|| self.downcast_ref::<Diagnostic>().map(Get::kind))
|
|
||||||
.or_else(|| self.downcast_ref::<reqwest::Error>().map(Get::kind))
|
.or_else(|| self.downcast_ref::<reqwest::Error>().map(Get::kind))
|
||||||
.or_else(|| self.downcast_ref::<ImportMapError>().map(Get::kind))
|
.or_else(|| self.downcast_ref::<ImportMapError>().map(Get::kind))
|
||||||
.or_else(|| self.downcast_ref::<io::Error>().map(Get::kind))
|
.or_else(|| self.downcast_ref::<io::Error>().map(Get::kind))
|
||||||
.or_else(|| self.downcast_ref::<JSError>().map(Get::kind))
|
|
||||||
.or_else(|| self.downcast_ref::<ModuleResolutionError>().map(Get::kind))
|
.or_else(|| self.downcast_ref::<ModuleResolutionError>().map(Get::kind))
|
||||||
.or_else(|| self.downcast_ref::<StaticError>().map(Get::kind))
|
.or_else(|| self.downcast_ref::<StaticError>().map(Get::kind))
|
||||||
.or_else(|| self.downcast_ref::<url::ParseError>().map(Get::kind))
|
.or_else(|| self.downcast_ref::<url::ParseError>().map(Get::kind))
|
||||||
|
@ -294,93 +332,7 @@ impl GetErrorKind for dyn AnyError {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::colors::strip_ansi_codes;
|
|
||||||
use crate::diagnostics::Diagnostic;
|
|
||||||
use crate::diagnostics::DiagnosticCategory;
|
|
||||||
use crate::diagnostics::DiagnosticItem;
|
|
||||||
use deno_core::ErrBox;
|
use deno_core::ErrBox;
|
||||||
use deno_core::StackFrame;
|
|
||||||
use deno_core::V8Exception;
|
|
||||||
|
|
||||||
fn js_error() -> JSError {
|
|
||||||
JSError::new(V8Exception {
|
|
||||||
message: "Error: foo bar".to_string(),
|
|
||||||
source_line: None,
|
|
||||||
script_resource_name: None,
|
|
||||||
line_number: None,
|
|
||||||
start_position: None,
|
|
||||||
end_position: None,
|
|
||||||
error_level: None,
|
|
||||||
start_column: None,
|
|
||||||
end_column: None,
|
|
||||||
frames: vec![
|
|
||||||
StackFrame {
|
|
||||||
line: 4,
|
|
||||||
column: 16,
|
|
||||||
script_name: "foo_bar.ts".to_string(),
|
|
||||||
function_name: "foo".to_string(),
|
|
||||||
is_eval: false,
|
|
||||||
is_constructor: false,
|
|
||||||
is_wasm: false,
|
|
||||||
},
|
|
||||||
StackFrame {
|
|
||||||
line: 5,
|
|
||||||
column: 20,
|
|
||||||
script_name: "bar_baz.ts".to_string(),
|
|
||||||
function_name: "qat".to_string(),
|
|
||||||
is_eval: false,
|
|
||||||
is_constructor: false,
|
|
||||||
is_wasm: false,
|
|
||||||
},
|
|
||||||
StackFrame {
|
|
||||||
line: 1,
|
|
||||||
column: 1,
|
|
||||||
script_name: "deno_main.js".to_string(),
|
|
||||||
function_name: "".to_string(),
|
|
||||||
is_eval: false,
|
|
||||||
is_constructor: false,
|
|
||||||
is_wasm: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn diagnostic() -> Diagnostic {
|
|
||||||
Diagnostic {
|
|
||||||
items: vec![
|
|
||||||
DiagnosticItem {
|
|
||||||
message: "Example 1".to_string(),
|
|
||||||
message_chain: None,
|
|
||||||
code: 2322,
|
|
||||||
category: DiagnosticCategory::Error,
|
|
||||||
start_position: Some(267),
|
|
||||||
end_position: Some(273),
|
|
||||||
source_line: Some(" values: o => [".to_string()),
|
|
||||||
line_number: Some(18),
|
|
||||||
script_resource_name: Some(
|
|
||||||
"deno/tests/complex_diagnostics.ts".to_string(),
|
|
||||||
),
|
|
||||||
start_column: Some(2),
|
|
||||||
end_column: Some(8),
|
|
||||||
related_information: None,
|
|
||||||
},
|
|
||||||
DiagnosticItem {
|
|
||||||
message: "Example 2".to_string(),
|
|
||||||
message_chain: None,
|
|
||||||
code: 2000,
|
|
||||||
category: DiagnosticCategory::Error,
|
|
||||||
start_position: Some(2),
|
|
||||||
end_position: Some(2),
|
|
||||||
source_line: Some(" values: undefined,".to_string()),
|
|
||||||
line_number: Some(128),
|
|
||||||
script_resource_name: Some("/foo/bar.ts".to_string()),
|
|
||||||
start_column: Some(2),
|
|
||||||
end_column: Some(8),
|
|
||||||
related_information: None,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn io_error() -> io::Error {
|
fn io_error() -> io::Error {
|
||||||
io::Error::from(io::ErrorKind::NotFound)
|
io::Error::from(io::ErrorKind::NotFound)
|
||||||
|
@ -414,26 +366,12 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_url_error() {
|
fn test_url_error() {
|
||||||
let err = ErrBox::from(url_error());
|
let err = ErrBox::from(url_error());
|
||||||
assert_eq!(err.kind(), ErrorKind::UrlParse);
|
assert_eq!(err.kind(), ErrorKind::URIError);
|
||||||
assert_eq!(err.to_string(), "empty host");
|
assert_eq!(err.to_string(), "empty host");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO find a way to easily test tokio errors and unix errors
|
// TODO find a way to easily test tokio errors and unix errors
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_diagnostic() {
|
|
||||||
let err = ErrBox::from(diagnostic());
|
|
||||||
assert_eq!(err.kind(), ErrorKind::Diagnostic);
|
|
||||||
assert_eq!(strip_ansi_codes(&err.to_string()), "error TS2322: Example 1\n\n► deno/tests/complex_diagnostics.ts:19:3\n\n19 values: o => [\n ~~~~~~\n\nerror TS2000: Example 2\n\n► /foo/bar.ts:129:3\n\n129 values: undefined,\n ~~~~~~\n\n\nFound 2 errors.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_js_error() {
|
|
||||||
let err = ErrBox::from(js_error());
|
|
||||||
assert_eq!(err.kind(), ErrorKind::JSError);
|
|
||||||
assert_eq!(strip_ansi_codes(&err.to_string()), "error: Error: foo bar\n at foo (foo_bar.ts:5:17)\n at qat (bar_baz.ts:6:21)\n at deno_main.js:2:2");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_import_map_error() {
|
fn test_import_map_error() {
|
||||||
let err = ErrBox::from(import_map_error());
|
let err = ErrBox::from(import_map_error());
|
||||||
|
@ -466,7 +404,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_buffer_specified() {
|
fn test_no_buffer_specified() {
|
||||||
let err = no_buffer_specified();
|
let err = no_buffer_specified();
|
||||||
assert_eq!(err.kind(), ErrorKind::InvalidInput);
|
assert_eq!(err.kind(), ErrorKind::TypeError);
|
||||||
assert_eq!(err.to_string(), "no buffer specified");
|
assert_eq!(err.to_string(), "no buffer specified");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ impl SourceFileFetcher {
|
||||||
fn fetch_local_file(&self, module_url: &Url) -> Result<SourceFile, ErrBox> {
|
fn fetch_local_file(&self, module_url: &Url) -> Result<SourceFile, ErrBox> {
|
||||||
let filepath = module_url.to_file_path().map_err(|()| {
|
let filepath = module_url.to_file_path().map_err(|()| {
|
||||||
ErrBox::from(DenoError::new(
|
ErrBox::from(DenoError::new(
|
||||||
ErrorKind::InvalidPath,
|
ErrorKind::URIError,
|
||||||
"File URL contains invalid path".to_owned(),
|
"File URL contains invalid path".to_owned(),
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
import { Reader, Writer, EOF, SyncReader, SyncWriter } from "./io.ts";
|
import { Reader, Writer, EOF, SyncReader, SyncWriter } from "./io.ts";
|
||||||
import { assert } from "./util.ts";
|
import { assert } from "./util.ts";
|
||||||
import { TextDecoder } from "./text_encoding.ts";
|
import { TextDecoder } from "./text_encoding.ts";
|
||||||
import { DenoError, ErrorKind } from "./errors.ts";
|
|
||||||
|
|
||||||
// MIN_READ is the minimum ArrayBuffer size passed to a read call by
|
// MIN_READ is the minimum ArrayBuffer size passed to a read call by
|
||||||
// buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond
|
// buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond
|
||||||
|
@ -162,7 +161,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
|
||||||
|
|
||||||
/** _grow() grows the buffer to guarantee space for n more bytes.
|
/** _grow() grows the buffer to guarantee space for n more bytes.
|
||||||
* It returns the index where bytes should be written.
|
* It returns the index where bytes should be written.
|
||||||
* If the buffer can't grow it will throw with ErrTooLarge.
|
* If the buffer can't grow it will throw with Error.
|
||||||
*/
|
*/
|
||||||
private _grow(n: number): number {
|
private _grow(n: number): number {
|
||||||
const m = this.length;
|
const m = this.length;
|
||||||
|
@ -183,10 +182,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
|
||||||
// don't spend all our time copying.
|
// don't spend all our time copying.
|
||||||
copyBytes(this.buf, this.buf.subarray(this.off));
|
copyBytes(this.buf, this.buf.subarray(this.off));
|
||||||
} else if (c > MAX_SIZE - c - n) {
|
} else if (c > MAX_SIZE - c - n) {
|
||||||
throw new DenoError(
|
throw new Error("The buffer cannot be grown beyond the maximum size.");
|
||||||
ErrorKind.TooLarge,
|
|
||||||
"The buffer cannot be grown beyond the maximum size."
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Not enough space anywhere, we need to allocate.
|
// Not enough space anywhere, we need to allocate.
|
||||||
const buf = new Uint8Array(2 * c + n);
|
const buf = new Uint8Array(2 * c + n);
|
||||||
|
@ -202,7 +198,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
|
||||||
/** grow() grows the buffer's capacity, if necessary, to guarantee space for
|
/** grow() grows the buffer's capacity, if necessary, to guarantee space for
|
||||||
* another n bytes. After grow(n), at least n bytes can be written to the
|
* another n bytes. After grow(n), at least n bytes can be written to the
|
||||||
* buffer without another allocation. If n is negative, grow() will panic. If
|
* buffer without another allocation. If n is negative, grow() will panic. If
|
||||||
* the buffer can't grow it will throw ErrTooLarge.
|
* the buffer can't grow it will throw Error.
|
||||||
* Based on https://golang.org/pkg/bytes/#Buffer.Grow
|
* Based on https://golang.org/pkg/bytes/#Buffer.Grow
|
||||||
*/
|
*/
|
||||||
grow(n: number): void {
|
grow(n: number): void {
|
||||||
|
@ -215,7 +211,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
|
||||||
|
|
||||||
/** readFrom() reads data from r until EOF and appends it to the buffer,
|
/** readFrom() reads data from r until EOF and appends it to the buffer,
|
||||||
* growing the buffer as needed. It returns the number of bytes read. If the
|
* growing the buffer as needed. It returns the number of bytes read. If the
|
||||||
* buffer becomes too large, readFrom will panic with ErrTooLarge.
|
* buffer becomes too large, readFrom will panic with Error.
|
||||||
* Based on https://golang.org/pkg/bytes/#Buffer.ReadFrom
|
* Based on https://golang.org/pkg/bytes/#Buffer.ReadFrom
|
||||||
*/
|
*/
|
||||||
async readFrom(r: Reader): Promise<number> {
|
async readFrom(r: Reader): Promise<number> {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// This code has been ported almost directly from Go's src/bytes/buffer_test.go
|
// This code has been ported almost directly from Go's src/bytes/buffer_test.go
|
||||||
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
||||||
// https://github.com/golang/go/blob/master/LICENSE
|
// https://github.com/golang/go/blob/master/LICENSE
|
||||||
import { assert, assertEquals, test } from "./test_util.ts";
|
import { assertEquals, assert, assertStrContains, test } from "./test_util.ts";
|
||||||
|
|
||||||
const { Buffer, readAll, readAllSync, writeAll, writeAllSync } = Deno;
|
const { Buffer, readAll, readAllSync, writeAll, writeAllSync } = Deno;
|
||||||
type Buffer = Deno.Buffer;
|
type Buffer = Deno.Buffer;
|
||||||
|
@ -159,8 +159,8 @@ test(async function bufferTooLargeByteWrites(): Promise<void> {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(err.kind, Deno.ErrorKind.TooLarge);
|
assert(err instanceof Error);
|
||||||
assertEquals(err.name, "TooLarge");
|
assertStrContains(err.message, "grown beyond the maximum size");
|
||||||
});
|
});
|
||||||
|
|
||||||
test(async function bufferLargeByteReads(): Promise<void> {
|
test(async function bufferLargeByteReads(): Promise<void> {
|
||||||
|
|
|
@ -60,8 +60,7 @@ testPerm({ write: true }, function chmodSyncFailure(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ write: false }, function chmodSyncPerm(): void {
|
testPerm({ write: false }, function chmodSyncPerm(): void {
|
||||||
|
@ -71,7 +70,7 @@ testPerm({ write: false }, function chmodSyncPerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -134,8 +133,7 @@ testPerm({ write: true }, async function chmodFailure(): Promise<void> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ write: false }, async function chmodPerm(): Promise<void> {
|
testPerm({ write: false }, async function chmodPerm(): Promise<void> {
|
||||||
|
@ -145,6 +143,6 @@ testPerm({ write: false }, async function chmodPerm(): Promise<void> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { testPerm, assertEquals } from "./test_util.ts";
|
import { testPerm, assertEquals, assert } from "./test_util.ts";
|
||||||
|
|
||||||
// chown on Windows is noop for now, so ignore its testing on Windows
|
// chown on Windows is noop for now, so ignore its testing on Windows
|
||||||
if (Deno.build.os !== "win") {
|
if (Deno.build.os !== "win") {
|
||||||
|
@ -31,8 +31,7 @@ if (Deno.build.os !== "win") {
|
||||||
try {
|
try {
|
||||||
await Deno.chown(filePath, 1000, 1000);
|
await Deno.chown(filePath, 1000, 1000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,8 +44,7 @@ if (Deno.build.os !== "win") {
|
||||||
try {
|
try {
|
||||||
Deno.chownSync(filePath, uid, gid);
|
Deno.chownSync(filePath, uid, gid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
assertEquals(e.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -60,8 +58,7 @@ if (Deno.build.os !== "win") {
|
||||||
try {
|
try {
|
||||||
await Deno.chown(filePath, uid, gid);
|
await Deno.chown(filePath, uid, gid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
assertEquals(e.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -77,8 +74,7 @@ if (Deno.build.os !== "win") {
|
||||||
// try changing the file's owner to root
|
// try changing the file's owner to root
|
||||||
Deno.chownSync(filePath, 0, 0);
|
Deno.chownSync(filePath, 0, 0);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
Deno.removeSync(dirPath, { recursive: true });
|
Deno.removeSync(dirPath, { recursive: true });
|
||||||
});
|
});
|
||||||
|
@ -96,8 +92,7 @@ if (Deno.build.os !== "win") {
|
||||||
// try changing the file's owner to root
|
// try changing the file's owner to root
|
||||||
await Deno.chown(filePath, 0, 0);
|
await Deno.chown(filePath, 0, 0);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
await Deno.remove(dirPath, { recursive: true });
|
await Deno.remove(dirPath, { recursive: true });
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,8 +43,7 @@ testPerm({ write: true, read: true }, function copyFileSyncFailure(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ write: true, read: false }, function copyFileSyncPerm1(): void {
|
testPerm({ write: true, read: false }, function copyFileSyncPerm1(): void {
|
||||||
|
@ -53,8 +52,7 @@ testPerm({ write: true, read: false }, function copyFileSyncPerm1(): void {
|
||||||
Deno.copyFileSync("/from.txt", "/to.txt");
|
Deno.copyFileSync("/from.txt", "/to.txt");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -65,8 +63,7 @@ testPerm({ write: false, read: true }, function copyFileSyncPerm2(): void {
|
||||||
Deno.copyFileSync("/from.txt", "/to.txt");
|
Deno.copyFileSync("/from.txt", "/to.txt");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -113,8 +110,7 @@ testPerm({ read: true, write: true }, async function copyFileFailure(): Promise<
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm(
|
testPerm(
|
||||||
|
@ -142,8 +138,7 @@ testPerm({ read: false, write: true }, async function copyFilePerm1(): Promise<
|
||||||
await Deno.copyFile("/from.txt", "/to.txt");
|
await Deno.copyFile("/from.txt", "/to.txt");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -156,8 +151,7 @@ testPerm({ read: true, write: false }, async function copyFilePerm2(): Promise<
|
||||||
await Deno.copyFile("/from.txt", "/to.txt");
|
await Deno.copyFile("/from.txt", "/to.txt");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,7 @@ export {
|
||||||
} from "./diagnostics.ts";
|
} from "./diagnostics.ts";
|
||||||
export { chdir, cwd } from "./dir.ts";
|
export { chdir, cwd } from "./dir.ts";
|
||||||
export { applySourceMap } from "./error_stack.ts";
|
export { applySourceMap } from "./error_stack.ts";
|
||||||
export { ErrorKind, DenoError } from "./errors.ts";
|
export { Err } from "./errors.ts";
|
||||||
export { FileInfo } from "./file_info.ts";
|
export { FileInfo } from "./file_info.ts";
|
||||||
export {
|
export {
|
||||||
File,
|
File,
|
||||||
|
|
|
@ -29,7 +29,7 @@ testPerm({ write: true }, function dirCwdError(): void {
|
||||||
Deno.cwd();
|
Deno.cwd();
|
||||||
throw Error("current directory removed, should throw error");
|
throw Error("current directory removed, should throw error");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof Deno.DenoError) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
console.log(err.name === "NotFound");
|
console.log(err.name === "NotFound");
|
||||||
} else {
|
} else {
|
||||||
throw Error("raised different exception");
|
throw Error("raised different exception");
|
||||||
|
@ -45,7 +45,7 @@ testPerm({ write: true }, function dirChdirError(): void {
|
||||||
Deno.chdir(path);
|
Deno.chdir(path);
|
||||||
throw Error("directory not available, should throw error");
|
throw Error("directory not available, should throw error");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof Deno.DenoError) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
console.log(err.name === "NotFound");
|
console.log(err.name === "NotFound");
|
||||||
} else {
|
} else {
|
||||||
throw Error("raised different exception");
|
throw Error("raised different exception");
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import * as util from "./util.ts";
|
import * as util from "./util.ts";
|
||||||
import { TextEncoder, TextDecoder } from "./text_encoding.ts";
|
import { TextEncoder, TextDecoder } from "./text_encoding.ts";
|
||||||
import { core } from "./core.ts";
|
import { core } from "./core.ts";
|
||||||
import { ErrorKind, DenoError } from "./errors.ts";
|
import { ErrorKind, constructError } from "./errors.ts";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
type Ok = any;
|
type Ok = any;
|
||||||
|
@ -37,7 +37,7 @@ function encode(args: object): Uint8Array {
|
||||||
|
|
||||||
function unwrapResponse(res: JsonResponse): Ok {
|
function unwrapResponse(res: JsonResponse): Ok {
|
||||||
if (res.err != null) {
|
if (res.err != null) {
|
||||||
throw new DenoError(res.err!.kind, res.err!.message);
|
return constructError(res.err!.kind, res.err!.message);
|
||||||
}
|
}
|
||||||
util.assert(res.ok != null);
|
util.assert(res.ok != null);
|
||||||
return res.ok;
|
return res.ok;
|
||||||
|
|
|
@ -2,7 +2,6 @@ import {
|
||||||
test,
|
test,
|
||||||
testPerm,
|
testPerm,
|
||||||
assert,
|
assert,
|
||||||
assertEquals,
|
|
||||||
assertMatch,
|
assertMatch,
|
||||||
unreachable
|
unreachable
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
|
@ -31,5 +30,4 @@ test(async function malformedJsonControlBuffer(): Promise<void> {
|
||||||
const resJson = JSON.parse(resText) as any;
|
const resJson = JSON.parse(resText) as any;
|
||||||
assert(!resJson.ok);
|
assert(!resJson.ok);
|
||||||
assert(resJson.err);
|
assert(resJson.err);
|
||||||
assertEquals(resJson.err!.kind, Deno.ErrorKind.InvalidInput);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import * as util from "./util.ts";
|
import * as util from "./util.ts";
|
||||||
import { core } from "./core.ts";
|
import { core } from "./core.ts";
|
||||||
import { TextDecoder } from "./text_encoding.ts";
|
import { TextDecoder } from "./text_encoding.ts";
|
||||||
import { ErrorKind, DenoError } from "./errors.ts";
|
import { Err, ErrorKind, constructError } from "./errors.ts";
|
||||||
|
|
||||||
const promiseTableMin = new Map<number, util.Resolvable<RecordMinimal>>();
|
const promiseTableMin = new Map<number, util.Resolvable<RecordMinimal>>();
|
||||||
// Note it's important that promiseId starts at 1 instead of 0, because sync
|
// Note it's important that promiseId starts at 1 instead of 0, because sync
|
||||||
|
@ -43,7 +43,7 @@ export function recordFromBufMinimal(ui8: Uint8Array): RecordMinimal {
|
||||||
const message = decoder.decode(ui8.slice(12));
|
const message = decoder.decode(ui8.slice(12));
|
||||||
err = { kind, message };
|
err = { kind, message };
|
||||||
} else if (ui8.length != 12) {
|
} else if (ui8.length != 12) {
|
||||||
err = { kind: ErrorKind.InvalidData, message: "Bad message" };
|
throw new Err.InvalidData("BadMessage");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -56,7 +56,7 @@ export function recordFromBufMinimal(ui8: Uint8Array): RecordMinimal {
|
||||||
|
|
||||||
function unwrapResponse(res: RecordMinimal): number {
|
function unwrapResponse(res: RecordMinimal): number {
|
||||||
if (res.err != null) {
|
if (res.err != null) {
|
||||||
throw new DenoError(res.err!.kind, res.err!.message);
|
return constructError(res.err!.kind, res.err!.message);
|
||||||
}
|
}
|
||||||
return res.result;
|
return res.result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,7 @@ test(async function malformedMinimalControlBuffer(): Promise<void> {
|
||||||
header.byteLength / 4
|
header.byteLength / 4
|
||||||
);
|
);
|
||||||
const arg = buf32[1];
|
const arg = buf32[1];
|
||||||
const result = buf32[2];
|
|
||||||
const message = new TextDecoder().decode(res.slice(12)).trim();
|
const message = new TextDecoder().decode(res.slice(12)).trim();
|
||||||
assert(arg < 0);
|
assert(arg < 0);
|
||||||
assertEquals(result, Deno.ErrorKind.InvalidInput);
|
|
||||||
assertEquals(message, "Unparsable control buffer");
|
assertEquals(message, "Unparsable control buffer");
|
||||||
});
|
});
|
||||||
|
|
217
cli/js/errors.ts
217
cli/js/errors.ts
|
@ -1,27 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
/** A Deno specific error. The `kind` property is set to a specific error code
|
|
||||||
* which can be used to in application logic.
|
|
||||||
*
|
|
||||||
* try {
|
|
||||||
* somethingThatMightThrow();
|
|
||||||
* } catch (e) {
|
|
||||||
* if (
|
|
||||||
* e instanceof Deno.DenoError &&
|
|
||||||
* e.kind === Deno.ErrorKind.NotFound
|
|
||||||
* ) {
|
|
||||||
* console.error("NotFound error!");
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
export class DenoError<T extends ErrorKind> extends Error {
|
|
||||||
constructor(readonly kind: T, msg: string) {
|
|
||||||
super(msg);
|
|
||||||
this.name = ErrorKind[kind];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warning! The values in this enum are duplicated in cli/msg.rs
|
// Warning! The values in this enum are duplicated in cli/msg.rs
|
||||||
// Update carefully!
|
// Update carefully!
|
||||||
export enum ErrorKind {
|
export enum ErrorKind {
|
||||||
|
@ -35,22 +13,189 @@ export enum ErrorKind {
|
||||||
AddrNotAvailable = 8,
|
AddrNotAvailable = 8,
|
||||||
BrokenPipe = 9,
|
BrokenPipe = 9,
|
||||||
AlreadyExists = 10,
|
AlreadyExists = 10,
|
||||||
WouldBlock = 11,
|
|
||||||
InvalidInput = 12,
|
|
||||||
InvalidData = 13,
|
InvalidData = 13,
|
||||||
TimedOut = 14,
|
TimedOut = 14,
|
||||||
Interrupted = 15,
|
Interrupted = 15,
|
||||||
WriteZero = 16,
|
WriteZero = 16,
|
||||||
Other = 17,
|
UnexpectedEof = 17,
|
||||||
UnexpectedEof = 18,
|
BadResource = 18,
|
||||||
BadResource = 19,
|
Http = 19,
|
||||||
UrlParse = 20,
|
URIError = 20,
|
||||||
Http = 21,
|
TypeError = 21,
|
||||||
TooLarge = 22,
|
Other = 22
|
||||||
InvalidSeekMode = 23,
|
|
||||||
UnixError = 24,
|
|
||||||
InvalidPath = 25,
|
|
||||||
ImportPrefixMissing = 26,
|
|
||||||
Diagnostic = 27,
|
|
||||||
JSError = 28
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function constructError(kind: ErrorKind, msg: string): never {
|
||||||
|
switch (kind) {
|
||||||
|
case ErrorKind.TypeError:
|
||||||
|
throw new TypeError(msg);
|
||||||
|
case ErrorKind.Other:
|
||||||
|
throw new Error(msg);
|
||||||
|
case ErrorKind.URIError:
|
||||||
|
throw new URIError(msg);
|
||||||
|
case ErrorKind.NotFound:
|
||||||
|
throw new NotFound(msg);
|
||||||
|
case ErrorKind.PermissionDenied:
|
||||||
|
throw new PermissionDenied(msg);
|
||||||
|
case ErrorKind.ConnectionRefused:
|
||||||
|
throw new ConnectionRefused(msg);
|
||||||
|
case ErrorKind.ConnectionReset:
|
||||||
|
throw new ConnectionReset(msg);
|
||||||
|
case ErrorKind.ConnectionAborted:
|
||||||
|
throw new ConnectionAborted(msg);
|
||||||
|
case ErrorKind.NotConnected:
|
||||||
|
throw new NotConnected(msg);
|
||||||
|
case ErrorKind.AddrInUse:
|
||||||
|
throw new AddrInUse(msg);
|
||||||
|
case ErrorKind.AddrNotAvailable:
|
||||||
|
throw new AddrNotAvailable(msg);
|
||||||
|
case ErrorKind.BrokenPipe:
|
||||||
|
throw new BrokenPipe(msg);
|
||||||
|
case ErrorKind.AlreadyExists:
|
||||||
|
throw new AlreadyExists(msg);
|
||||||
|
case ErrorKind.InvalidData:
|
||||||
|
throw new InvalidData(msg);
|
||||||
|
case ErrorKind.TimedOut:
|
||||||
|
throw new TimedOut(msg);
|
||||||
|
case ErrorKind.Interrupted:
|
||||||
|
throw new Interrupted(msg);
|
||||||
|
case ErrorKind.WriteZero:
|
||||||
|
throw new WriteZero(msg);
|
||||||
|
case ErrorKind.UnexpectedEof:
|
||||||
|
throw new UnexpectedEof(msg);
|
||||||
|
case ErrorKind.BadResource:
|
||||||
|
throw new BadResource(msg);
|
||||||
|
case ErrorKind.Http:
|
||||||
|
throw new Http(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NotFound extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "NotFound";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class PermissionDenied extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "PermissionDenied";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class ConnectionRefused extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "ConnectionRefused";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class ConnectionReset extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "ConnectionReset";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class ConnectionAborted extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "ConnectionAborted";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class NotConnected extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "NotConnected";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class AddrInUse extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "AddrInUse";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class AddrNotAvailable extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "AddrNotAvailable";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class BrokenPipe extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "BrokenPipe";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class AlreadyExists extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "AlreadyExists";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class InvalidData extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "InvalidData";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class TimedOut extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "TimedOut";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Interrupted extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "Interrupted";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class WriteZero extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "WriteZero";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Other extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "Other";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class UnexpectedEof extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "UnexpectedEof";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class BadResource extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "BadResource";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Http extends Error {
|
||||||
|
constructor(msg: string) {
|
||||||
|
super(msg);
|
||||||
|
this.name = "Http";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Err = {
|
||||||
|
NotFound: NotFound,
|
||||||
|
PermissionDenied: PermissionDenied,
|
||||||
|
ConnectionRefused: ConnectionRefused,
|
||||||
|
ConnectionReset: ConnectionReset,
|
||||||
|
ConnectionAborted: ConnectionAborted,
|
||||||
|
NotConnected: NotConnected,
|
||||||
|
AddrInUse: AddrInUse,
|
||||||
|
AddrNotAvailable: AddrNotAvailable,
|
||||||
|
BrokenPipe: BrokenPipe,
|
||||||
|
AlreadyExists: AlreadyExists,
|
||||||
|
InvalidData: InvalidData,
|
||||||
|
TimedOut: TimedOut,
|
||||||
|
Interrupted: Interrupted,
|
||||||
|
WriteZero: WriteZero,
|
||||||
|
Other: Other,
|
||||||
|
UnexpectedEof: UnexpectedEof,
|
||||||
|
BadResource: BadResource,
|
||||||
|
Http: Http
|
||||||
|
};
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import * as domTypes from "./dom_types.ts";
|
import * as domTypes from "./dom_types.ts";
|
||||||
import { DenoError, ErrorKind } from "./errors.ts";
|
|
||||||
import { hasOwnProperty, requiredArguments } from "./util.ts";
|
import { hasOwnProperty, requiredArguments } from "./util.ts";
|
||||||
import {
|
import {
|
||||||
getRoot,
|
getRoot,
|
||||||
|
@ -134,17 +133,15 @@ export class EventTarget implements domTypes.EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.dispatched || !event.initialized) {
|
if (event.dispatched || !event.initialized) {
|
||||||
throw new DenoError(
|
// TODO(bartlomieju): very likely that different error
|
||||||
ErrorKind.InvalidData,
|
// should be thrown here (DOMException?)
|
||||||
"Tried to dispatch an uninitialized event"
|
throw new TypeError("Tried to dispatch an uninitialized event");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.eventPhase !== domTypes.EventPhase.NONE) {
|
if (event.eventPhase !== domTypes.EventPhase.NONE) {
|
||||||
throw new DenoError(
|
// TODO(bartlomieju): very likely that different error
|
||||||
ErrorKind.InvalidData,
|
// should be thrown here (DOMException?)
|
||||||
"Tried to dispatch a dispatching event"
|
throw new TypeError("Tried to dispatch a dispatching event");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventTargetHelpers.dispatch(this_, event);
|
return eventTargetHelpers.dispatch(this_, event);
|
||||||
|
@ -418,7 +415,9 @@ const eventTargetHelpers = {
|
||||||
try {
|
try {
|
||||||
listener.handleEvent(eventImpl);
|
listener.handleEvent(eventImpl);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DenoError(ErrorKind.Interrupted, error.message);
|
// TODO(bartlomieju): very likely that different error
|
||||||
|
// should be thrown here (DOMException?)
|
||||||
|
throw new Error(error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
eventImpl.inPassiveListener = false;
|
eventImpl.inPassiveListener = false;
|
||||||
|
|
|
@ -16,8 +16,7 @@ testPerm({ net: true }, async function fetchConnectionError(): Promise<void> {
|
||||||
} catch (err_) {
|
} catch (err_) {
|
||||||
err = err_;
|
err = err_;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.Http);
|
assert(err instanceof Deno.Err.Http);
|
||||||
assertEquals(err.name, "Http");
|
|
||||||
assertStrContains(err.message, "error trying to connect");
|
assertStrContains(err.message, "error trying to connect");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -34,7 +33,7 @@ test(async function fetchPerm(): Promise<void> {
|
||||||
} catch (err_) {
|
} catch (err_) {
|
||||||
err = err_;
|
err = err_;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -107,8 +106,7 @@ testPerm({ net: true }, async function fetchEmptyInvalid(): Promise<void> {
|
||||||
} catch (err_) {
|
} catch (err_) {
|
||||||
err = err_;
|
err = err_;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.UrlParse);
|
assert(err instanceof URIError);
|
||||||
assertEquals(err.name, "UrlParse");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ net: true }, async function fetchMultipartFormDataSuccess(): Promise<
|
testPerm({ net: true }, async function fetchMultipartFormDataSuccess(): Promise<
|
||||||
|
|
|
@ -79,7 +79,7 @@ testPerm({ write: false }, async function writePermFailure(): Promise<void> {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -136,8 +136,7 @@ testPerm({ read: false }, async function readPermFailure(): Promise<void> {
|
||||||
await Deno.open("cli/tests/fixture.json", "r");
|
await Deno.open("cli/tests/fixture.json", "r");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -209,7 +208,7 @@ testPerm(
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -380,8 +379,8 @@ testPerm({ read: true }, async function seekMode(): Promise<void> {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.InvalidSeekMode);
|
assert(err instanceof TypeError);
|
||||||
assertEquals(err.name, "InvalidSeekMode");
|
assertStrContains(err.message, "Invalid seek mode");
|
||||||
|
|
||||||
// We should still be able to read the file
|
// We should still be able to read the file
|
||||||
// since it is still open.
|
// since it is still open.
|
||||||
|
|
111
cli/js/lib.deno.ns.d.ts
vendored
111
cli/js/lib.deno.ns.d.ts
vendored
|
@ -602,19 +602,19 @@ declare namespace Deno {
|
||||||
write(p: Uint8Array): Promise<number>;
|
write(p: Uint8Array): Promise<number>;
|
||||||
/** _grow() grows the buffer to guarantee space for n more bytes.
|
/** _grow() grows the buffer to guarantee space for n more bytes.
|
||||||
* It returns the index where bytes should be written.
|
* It returns the index where bytes should be written.
|
||||||
* If the buffer can't grow it will throw with ErrTooLarge.
|
* If the buffer can't grow it will throw with Error.
|
||||||
*/
|
*/
|
||||||
private _grow;
|
private _grow;
|
||||||
/** grow() grows the buffer's capacity, if necessary, to guarantee space for
|
/** grow() grows the buffer's capacity, if necessary, to guarantee space for
|
||||||
* another n bytes. After grow(n), at least n bytes can be written to the
|
* another n bytes. After grow(n), at least n bytes can be written to the
|
||||||
* buffer without another allocation. If n is negative, grow() will panic. If
|
* buffer without another allocation. If n is negative, grow() will panic. If
|
||||||
* the buffer can't grow it will throw ErrTooLarge.
|
* the buffer can't grow it will throw Error.
|
||||||
* Based on https://golang.org/pkg/bytes/#Buffer.Grow
|
* Based on https://golang.org/pkg/bytes/#Buffer.Grow
|
||||||
*/
|
*/
|
||||||
grow(n: number): void;
|
grow(n: number): void;
|
||||||
/** readFrom() reads data from r until EOF and appends it to the buffer,
|
/** readFrom() reads data from r until EOF and appends it to the buffer,
|
||||||
* growing the buffer as needed. It returns the number of bytes read. If the
|
* growing the buffer as needed. It returns the number of bytes read. If the
|
||||||
* buffer becomes too large, readFrom will panic with ErrTooLarge.
|
* buffer becomes too large, readFrom will panic with Error.
|
||||||
* Based on https://golang.org/pkg/bytes/#Buffer.ReadFrom
|
* Based on https://golang.org/pkg/bytes/#Buffer.ReadFrom
|
||||||
*/
|
*/
|
||||||
readFrom(r: Reader): Promise<number>;
|
readFrom(r: Reader): Promise<number>;
|
||||||
|
@ -1204,55 +1204,64 @@ declare namespace Deno {
|
||||||
*/
|
*/
|
||||||
export function applySourceMap(location: Location): Location;
|
export function applySourceMap(location: Location): Location;
|
||||||
|
|
||||||
/** A Deno specific error. The `kind` property is set to a specific error code
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
* which can be used to in application logic.
|
namespace Err {
|
||||||
*
|
class NotFound extends Error {
|
||||||
* try {
|
constructor(msg: string);
|
||||||
* somethingThatMightThrow();
|
}
|
||||||
* } catch (e) {
|
class PermissionDenied extends Error {
|
||||||
* if (
|
constructor(msg: string);
|
||||||
* e instanceof Deno.DenoError &&
|
}
|
||||||
* e.kind === Deno.ErrorKind.NotFound
|
class ConnectionRefused extends Error {
|
||||||
* ) {
|
constructor(msg: string);
|
||||||
* console.error("NotFound error!");
|
}
|
||||||
* }
|
class ConnectionReset extends Error {
|
||||||
* }
|
constructor(msg: string);
|
||||||
*
|
}
|
||||||
*/
|
class ConnectionAborted extends Error {
|
||||||
export class DenoError<T extends ErrorKind> extends Error {
|
constructor(msg: string);
|
||||||
readonly kind: T;
|
}
|
||||||
constructor(kind: T, msg: string);
|
class NotConnected extends Error {
|
||||||
}
|
constructor(msg: string);
|
||||||
export enum ErrorKind {
|
}
|
||||||
NotFound = 1,
|
class AddrInUse extends Error {
|
||||||
PermissionDenied = 2,
|
constructor(msg: string);
|
||||||
ConnectionRefused = 3,
|
}
|
||||||
ConnectionReset = 4,
|
class AddrNotAvailable extends Error {
|
||||||
ConnectionAborted = 5,
|
constructor(msg: string);
|
||||||
NotConnected = 6,
|
}
|
||||||
AddrInUse = 7,
|
class BrokenPipe extends Error {
|
||||||
AddrNotAvailable = 8,
|
constructor(msg: string);
|
||||||
BrokenPipe = 9,
|
}
|
||||||
AlreadyExists = 10,
|
class AlreadyExists extends Error {
|
||||||
WouldBlock = 11,
|
constructor(msg: string);
|
||||||
InvalidInput = 12,
|
}
|
||||||
InvalidData = 13,
|
class InvalidData extends Error {
|
||||||
TimedOut = 14,
|
constructor(msg: string);
|
||||||
Interrupted = 15,
|
}
|
||||||
WriteZero = 16,
|
class TimedOut extends Error {
|
||||||
Other = 17,
|
constructor(msg: string);
|
||||||
UnexpectedEof = 18,
|
}
|
||||||
BadResource = 19,
|
class Interrupted extends Error {
|
||||||
UrlParse = 20,
|
constructor(msg: string);
|
||||||
Http = 21,
|
}
|
||||||
TooLarge = 22,
|
class WriteZero extends Error {
|
||||||
InvalidSeekMode = 23,
|
constructor(msg: string);
|
||||||
UnixError = 24,
|
}
|
||||||
InvalidPath = 25,
|
class Other extends Error {
|
||||||
ImportPrefixMissing = 26,
|
constructor(msg: string);
|
||||||
Diagnostic = 27,
|
}
|
||||||
JSError = 28
|
class UnexpectedEof extends Error {
|
||||||
|
constructor(msg: string);
|
||||||
|
}
|
||||||
|
class BadResource extends Error {
|
||||||
|
constructor(msg: string);
|
||||||
|
}
|
||||||
|
class Http extends Error {
|
||||||
|
constructor(msg: string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
||||||
|
|
||||||
/** UNSTABLE: potentially want names to overlap more with browser.
|
/** UNSTABLE: potentially want names to overlap more with browser.
|
||||||
*
|
*
|
||||||
|
|
|
@ -43,8 +43,7 @@ testPerm({ read: true, write: true }, function linkSyncExists(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.AlreadyExists);
|
assert(err instanceof Deno.Err.AlreadyExists);
|
||||||
assertEquals(err.name, "AlreadyExists");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ read: true, write: true }, function linkSyncNotFound(): void {
|
testPerm({ read: true, write: true }, function linkSyncNotFound(): void {
|
||||||
|
@ -59,8 +58,7 @@ testPerm({ read: true, write: true }, function linkSyncNotFound(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ read: false, write: true }, function linkSyncReadPerm(): void {
|
testPerm({ read: false, write: true }, function linkSyncReadPerm(): void {
|
||||||
|
@ -70,7 +68,7 @@ testPerm({ read: false, write: true }, function linkSyncReadPerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -81,7 +79,7 @@ testPerm({ read: true, write: false }, function linkSyncWritePerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,7 @@ testPerm({ write: true }, function makeTempDirSyncSuccess(): void {
|
||||||
} catch (err_) {
|
} catch (err_) {
|
||||||
err = err_;
|
err = err_;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function makeTempDirSyncPerm(): void {
|
test(function makeTempDirSyncPerm(): void {
|
||||||
|
@ -35,7 +34,7 @@ test(function makeTempDirSyncPerm(): void {
|
||||||
} catch (err_) {
|
} catch (err_) {
|
||||||
err = err_;
|
err = err_;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -61,8 +60,7 @@ testPerm({ write: true }, async function makeTempDirSuccess(): Promise<void> {
|
||||||
} catch (err_) {
|
} catch (err_) {
|
||||||
err = err_;
|
err = err_;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ write: true }, function makeTempFileSyncSuccess(): void {
|
testPerm({ write: true }, function makeTempFileSyncSuccess(): void {
|
||||||
|
@ -88,8 +86,7 @@ testPerm({ write: true }, function makeTempFileSyncSuccess(): void {
|
||||||
} catch (err_) {
|
} catch (err_) {
|
||||||
err = err_;
|
err = err_;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function makeTempFileSyncPerm(): void {
|
test(function makeTempFileSyncPerm(): void {
|
||||||
|
@ -100,7 +97,7 @@ test(function makeTempFileSyncPerm(): void {
|
||||||
} catch (err_) {
|
} catch (err_) {
|
||||||
err = err_;
|
err = err_;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -127,6 +124,5 @@ testPerm({ write: true }, async function makeTempFileSuccess(): Promise<void> {
|
||||||
} catch (err_) {
|
} catch (err_) {
|
||||||
err = err_;
|
err = err_;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,7 +25,7 @@ testPerm({ write: false }, function mkdirSyncPerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,8 +45,7 @@ testPerm({ write: true }, function mkdirErrIfExists(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.AlreadyExists);
|
assert(err instanceof Deno.Err.AlreadyExists);
|
||||||
assertEquals(err.name, "AlreadyExists");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ read: true, write: true }, function mkdirSyncRecursive(): void {
|
testPerm({ read: true, write: true }, function mkdirSyncRecursive(): void {
|
||||||
|
|
|
@ -20,15 +20,14 @@ testPerm({ net: true }, async function netCloseWhileAccept(): Promise<void> {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.Other);
|
assert(err instanceof Error);
|
||||||
assertEquals(err.message, "Listener has been closed");
|
assertEquals(err.message, "Listener has been closed");
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ net: true }, async function netConcurrentAccept(): Promise<void> {
|
testPerm({ net: true }, async function netConcurrentAccept(): Promise<void> {
|
||||||
const listener = Deno.listen({ port: 4502 });
|
const listener = Deno.listen({ port: 4502 });
|
||||||
let acceptErrCount = 0;
|
let acceptErrCount = 0;
|
||||||
const checkErr = (e: Deno.DenoError<Deno.ErrorKind>): void => {
|
const checkErr = (e: Error): void => {
|
||||||
assertEquals(e.kind, Deno.ErrorKind.Other);
|
|
||||||
if (e.message === "Listener has been closed") {
|
if (e.message === "Listener has been closed") {
|
||||||
assertEquals(acceptErrCount, 1);
|
assertEquals(acceptErrCount, 1);
|
||||||
} else if (e.message === "Another accept task is ongoing") {
|
} else if (e.message === "Another accept task is ongoing") {
|
||||||
|
@ -170,8 +169,7 @@ testPerm({ net: true }, async function netDoubleCloseRead() {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotConnected);
|
assert(err instanceof Deno.Err.NotConnected);
|
||||||
assertEquals(err.name, "NotConnected");
|
|
||||||
closeDeferred.resolve();
|
closeDeferred.resolve();
|
||||||
listener.close();
|
listener.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
|
@ -205,8 +203,7 @@ testPerm({ net: true }, async function netCloseWriteSuccess() {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.BrokenPipe);
|
assert(err instanceof Deno.Err.BrokenPipe);
|
||||||
assertEquals(err.name, "BrokenPipe");
|
|
||||||
closeDeferred.resolve();
|
closeDeferred.resolve();
|
||||||
listener.close();
|
listener.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
|
@ -232,8 +229,7 @@ testPerm({ net: true }, async function netDoubleCloseWrite() {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotConnected);
|
assert(err instanceof Deno.Err.NotConnected);
|
||||||
assertEquals(err.name, "NotConnected");
|
|
||||||
closeDeferred.resolve();
|
closeDeferred.resolve();
|
||||||
listener.close();
|
listener.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import * as dispatch from "./dispatch.ts";
|
import * as dispatch from "./dispatch.ts";
|
||||||
import { sendSync } from "./dispatch_json.ts";
|
import { sendSync } from "./dispatch_json.ts";
|
||||||
import { ErrorKind } from "./errors.ts";
|
import { Err } from "./errors.ts";
|
||||||
import * as util from "./util.ts";
|
import * as util from "./util.ts";
|
||||||
|
|
||||||
/** Check if running in terminal.
|
/** Check if running in terminal.
|
||||||
|
@ -193,7 +193,7 @@ export function dir(kind: DirKind): string | null {
|
||||||
try {
|
try {
|
||||||
return sendSync(dispatch.OP_GET_DIR, { kind });
|
return sendSync(dispatch.OP_GET_DIR, { kind });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.kind == ErrorKind.PermissionDenied) {
|
if (error instanceof Err.PermissionDenied) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -31,7 +31,7 @@ test(function envPermissionDenied1(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertNotEquals(err, undefined);
|
assertNotEquals(err, undefined);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ test(function envPermissionDenied2(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertNotEquals(err, undefined);
|
assertNotEquals(err, undefined);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ testPerm({ env: true }, function getDir(): void {
|
||||||
testPerm({}, function getDirWithoutPermission(): void {
|
testPerm({}, function getDirWithoutPermission(): void {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
() => Deno.dir("home"),
|
() => Deno.dir("home"),
|
||||||
Deno.DenoError,
|
Deno.Err.PermissionDenied,
|
||||||
`run again with the --allow-env flag`
|
`run again with the --allow-env flag`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -277,7 +277,7 @@ testPerm({ env: false }, function execPathPerm(): void {
|
||||||
Deno.execPath();
|
Deno.execPath();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
|
@ -293,7 +293,7 @@ testPerm({ env: false }, function hostnamePerm(): void {
|
||||||
Deno.hostname();
|
Deno.hostname();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
|
|
|
@ -31,18 +31,26 @@ for (const grant of knownPermissions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
test(async function permissionInvalidName(): Promise<void> {
|
test(async function permissionInvalidName(): Promise<void> {
|
||||||
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
await Deno.permissions.query({ name: "foo" as any });
|
await Deno.permissions.query({ name: "foo" as any });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.name === "Other");
|
thrown = true;
|
||||||
|
assert(e instanceof Error);
|
||||||
|
} finally {
|
||||||
|
assert(thrown);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test(async function permissionNetInvalidUrl(): Promise<void> {
|
test(async function permissionNetInvalidUrl(): Promise<void> {
|
||||||
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
await Deno.permissions.query({ name: "net", url: ":" });
|
await Deno.permissions.query({ name: "net", url: ":" });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(e.name === "UrlParse");
|
thrown = true;
|
||||||
|
assert(e instanceof URIError);
|
||||||
|
} finally {
|
||||||
|
assert(thrown);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,16 +6,7 @@ import {
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertStrContains
|
assertStrContains
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
const {
|
const { kill, run, readFile, open, makeTempDir, writeFile } = Deno;
|
||||||
kill,
|
|
||||||
run,
|
|
||||||
DenoError,
|
|
||||||
ErrorKind,
|
|
||||||
readFile,
|
|
||||||
open,
|
|
||||||
makeTempDir,
|
|
||||||
writeFile
|
|
||||||
} = Deno;
|
|
||||||
|
|
||||||
test(function runPermissions(): void {
|
test(function runPermissions(): void {
|
||||||
let caughtError = false;
|
let caughtError = false;
|
||||||
|
@ -23,8 +14,7 @@ test(function runPermissions(): void {
|
||||||
Deno.run({ args: ["python", "-c", "print('hello world')"] });
|
Deno.run({ args: ["python", "-c", "print('hello world')"] });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -78,8 +68,7 @@ testPerm({ run: true }, function runNotFound(): void {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
assert(error !== undefined);
|
assert(error !== undefined);
|
||||||
assert(error instanceof DenoError);
|
assert(error instanceof Deno.Err.NotFound);
|
||||||
assertEquals(error.kind, ErrorKind.NotFound);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm(
|
testPerm(
|
||||||
|
@ -332,8 +321,7 @@ if (Deno.build.os !== "win") {
|
||||||
Deno.kill(Deno.pid, Deno.Signal.SIGCONT);
|
Deno.kill(Deno.pid, Deno.Signal.SIGCONT);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -370,8 +358,7 @@ if (Deno.build.os !== "win") {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.InvalidInput);
|
assert(err instanceof TypeError);
|
||||||
assertEquals(err.name, "InvalidInput");
|
|
||||||
|
|
||||||
p.close();
|
p.close();
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,8 +32,7 @@ testPerm({ read: false }, function readDirSyncPerm(): void {
|
||||||
Deno.readDirSync("tests/");
|
Deno.readDirSync("tests/");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -46,7 +45,7 @@ testPerm({ read: true }, function readDirSyncNotDir(): void {
|
||||||
src = Deno.readDirSync("cli/tests/fixture.json");
|
src = Deno.readDirSync("cli/tests/fixture.json");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(err.kind, Deno.ErrorKind.Other);
|
assert(err instanceof Error);
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
assertEquals(src, undefined);
|
assertEquals(src, undefined);
|
||||||
|
@ -60,7 +59,7 @@ testPerm({ read: true }, function readDirSyncNotFound(): void {
|
||||||
src = Deno.readDirSync("bad_dir_name");
|
src = Deno.readDirSync("bad_dir_name");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
assertEquals(src, undefined);
|
assertEquals(src, undefined);
|
||||||
|
@ -77,8 +76,7 @@ testPerm({ read: false }, async function readDirPerm(): Promise<void> {
|
||||||
await Deno.readDir("tests/");
|
await Deno.readDir("tests/");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,8 +16,7 @@ testPerm({ read: false }, function readFileSyncPerm(): void {
|
||||||
Deno.readFileSync("cli/tests/fixture.json");
|
Deno.readFileSync("cli/tests/fixture.json");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -29,7 +28,7 @@ testPerm({ read: true }, function readFileSyncNotFound(): void {
|
||||||
data = Deno.readFileSync("bad_filename");
|
data = Deno.readFileSync("bad_filename");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
assert(data === undefined);
|
assert(data === undefined);
|
||||||
|
@ -50,8 +49,7 @@ testPerm({ read: false }, async function readFilePerm(): Promise<void> {
|
||||||
await Deno.readFile("cli/tests/fixture.json");
|
await Deno.readFile("cli/tests/fixture.json");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,8 +21,7 @@ testPerm({ read: false }, async function readlinkSyncPerm(): Promise<void> {
|
||||||
Deno.readlinkSync("/symlink");
|
Deno.readlinkSync("/symlink");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -34,7 +33,7 @@ testPerm({ read: true }, function readlinkSyncNotFound(): void {
|
||||||
data = Deno.readlinkSync("bad_filename");
|
data = Deno.readlinkSync("bad_filename");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
assertEquals(data, undefined);
|
assertEquals(data, undefined);
|
||||||
|
@ -62,8 +61,7 @@ testPerm({ read: false }, async function readlinkPerm(): Promise<void> {
|
||||||
await Deno.readlink("/symlink");
|
await Deno.readlink("/symlink");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { testPerm, assert, assertEquals } from "./test_util.ts";
|
import { testPerm, assert } from "./test_util.ts";
|
||||||
|
|
||||||
testPerm({ read: true }, function realpathSyncSuccess(): void {
|
testPerm({ read: true }, function realpathSyncSuccess(): void {
|
||||||
const incompletePath = "cli/tests/fixture.json";
|
const incompletePath = "cli/tests/fixture.json";
|
||||||
|
@ -31,8 +31,7 @@ testPerm({ read: false }, function realpathSyncPerm(): void {
|
||||||
Deno.realpathSync("some_file");
|
Deno.realpathSync("some_file");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -43,7 +42,7 @@ testPerm({ read: true }, function realpathSyncNotFound(): void {
|
||||||
Deno.realpathSync("bad_filename");
|
Deno.realpathSync("bad_filename");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -81,8 +80,7 @@ testPerm({ read: false }, async function realpathPerm(): Promise<void> {
|
||||||
await Deno.realpath("some_file");
|
await Deno.realpath("some_file");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -93,7 +91,7 @@ testPerm({ read: true }, async function realpathNotFound(): Promise<void> {
|
||||||
await Deno.realpath("bad_filename");
|
await Deno.realpath("bad_filename");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,8 +18,7 @@ testPerm({ write: true, read: true }, function removeSyncDirSuccess(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// Directory is gone
|
// Directory is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ write: true, read: true }, function removeSyncFileSuccess(): void {
|
testPerm({ write: true, read: true }, function removeSyncFileSuccess(): void {
|
||||||
|
@ -39,8 +38,7 @@ testPerm({ write: true, read: true }, function removeSyncFileSuccess(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// File is gone
|
// File is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ write: true, read: true }, function removeSyncFail(): void {
|
testPerm({ write: true, read: true }, function removeSyncFail(): void {
|
||||||
|
@ -61,8 +59,7 @@ testPerm({ write: true, read: true }, function removeSyncFail(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// TODO(ry) Is Other really the error we should get here? What would Go do?
|
// TODO(ry) Is Other really the error we should get here? What would Go do?
|
||||||
assertEquals(err.kind, Deno.ErrorKind.Other);
|
assert(err instanceof Error);
|
||||||
assertEquals(err.name, "Other");
|
|
||||||
// NON-EXISTENT DIRECTORY/FILE
|
// NON-EXISTENT DIRECTORY/FILE
|
||||||
try {
|
try {
|
||||||
// Non-existent
|
// Non-existent
|
||||||
|
@ -70,8 +67,7 @@ testPerm({ write: true, read: true }, function removeSyncFail(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm(
|
testPerm(
|
||||||
|
@ -86,7 +82,6 @@ testPerm(
|
||||||
errOnWindows = err;
|
errOnWindows = err;
|
||||||
}
|
}
|
||||||
if (Deno.build.os === "win") {
|
if (Deno.build.os === "win") {
|
||||||
assertEquals(errOnWindows.kind, Deno.ErrorKind.Other);
|
|
||||||
assertEquals(errOnWindows.message, "Not implemented");
|
assertEquals(errOnWindows.message, "Not implemented");
|
||||||
} else {
|
} else {
|
||||||
const pathInfo = Deno.lstatSync(danglingSymlinkPath);
|
const pathInfo = Deno.lstatSync(danglingSymlinkPath);
|
||||||
|
@ -98,8 +93,7 @@ testPerm(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -121,7 +115,6 @@ testPerm(
|
||||||
errOnWindows = err;
|
errOnWindows = err;
|
||||||
}
|
}
|
||||||
if (Deno.build.os === "win") {
|
if (Deno.build.os === "win") {
|
||||||
assertEquals(errOnWindows.kind, Deno.ErrorKind.Other);
|
|
||||||
assertEquals(errOnWindows.message, "Not implemented");
|
assertEquals(errOnWindows.message, "Not implemented");
|
||||||
} else {
|
} else {
|
||||||
const symlinkPathInfo = Deno.statSync(validSymlinkPath);
|
const symlinkPathInfo = Deno.statSync(validSymlinkPath);
|
||||||
|
@ -134,8 +127,7 @@ testPerm(
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
Deno.removeSync(filePath);
|
Deno.removeSync(filePath);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -147,7 +139,7 @@ testPerm({ write: false }, function removeSyncPerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -166,8 +158,8 @@ testPerm({ write: true, read: true }, function removeAllSyncDirSuccess(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// Directory is gone
|
// Directory is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
// REMOVE NON-EMPTY DIRECTORY
|
// REMOVE NON-EMPTY DIRECTORY
|
||||||
path = Deno.makeTempDirSync() + "/dir/subdir";
|
path = Deno.makeTempDirSync() + "/dir/subdir";
|
||||||
const subPath = path + "/subsubdir";
|
const subPath = path + "/subsubdir";
|
||||||
|
@ -185,8 +177,7 @@ testPerm({ write: true, read: true }, function removeAllSyncDirSuccess(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// Directory is gone
|
// Directory is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm(
|
testPerm(
|
||||||
|
@ -208,8 +199,7 @@ testPerm(
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// File is gone
|
// File is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -222,8 +212,7 @@ testPerm({ write: true }, function removeAllSyncFail(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ write: false }, function removeAllSyncPerm(): void {
|
testPerm({ write: false }, function removeAllSyncPerm(): void {
|
||||||
|
@ -233,7 +222,7 @@ testPerm({ write: false }, function removeAllSyncPerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -256,8 +245,7 @@ testPerm(
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// Directory is gone
|
// Directory is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -280,8 +268,7 @@ testPerm(
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// File is gone
|
// File is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -304,8 +291,7 @@ testPerm({ write: true, read: true }, async function removeFail(): Promise<
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.Other);
|
assert(err instanceof Error);
|
||||||
assertEquals(err.name, "Other");
|
|
||||||
// NON-EXISTENT DIRECTORY/FILE
|
// NON-EXISTENT DIRECTORY/FILE
|
||||||
try {
|
try {
|
||||||
// Non-existent
|
// Non-existent
|
||||||
|
@ -313,8 +299,7 @@ testPerm({ write: true, read: true }, async function removeFail(): Promise<
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm(
|
testPerm(
|
||||||
|
@ -329,7 +314,6 @@ testPerm(
|
||||||
errOnWindows = e;
|
errOnWindows = e;
|
||||||
}
|
}
|
||||||
if (Deno.build.os === "win") {
|
if (Deno.build.os === "win") {
|
||||||
assertEquals(errOnWindows.kind, Deno.ErrorKind.Other);
|
|
||||||
assertEquals(errOnWindows.message, "Not implemented");
|
assertEquals(errOnWindows.message, "Not implemented");
|
||||||
} else {
|
} else {
|
||||||
const pathInfo = Deno.lstatSync(danglingSymlinkPath);
|
const pathInfo = Deno.lstatSync(danglingSymlinkPath);
|
||||||
|
@ -341,8 +325,7 @@ testPerm(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -364,7 +347,6 @@ testPerm(
|
||||||
errOnWindows = e;
|
errOnWindows = e;
|
||||||
}
|
}
|
||||||
if (Deno.build.os === "win") {
|
if (Deno.build.os === "win") {
|
||||||
assertEquals(errOnWindows.kind, Deno.ErrorKind.Other);
|
|
||||||
assertEquals(errOnWindows.message, "Not implemented");
|
assertEquals(errOnWindows.message, "Not implemented");
|
||||||
} else {
|
} else {
|
||||||
const symlinkPathInfo = Deno.statSync(validSymlinkPath);
|
const symlinkPathInfo = Deno.statSync(validSymlinkPath);
|
||||||
|
@ -377,8 +359,7 @@ testPerm(
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
Deno.removeSync(filePath);
|
Deno.removeSync(filePath);
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -390,7 +371,7 @@ testPerm({ write: false }, async function removePerm(): Promise<void> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -411,8 +392,8 @@ testPerm(
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// Directory is gone
|
// Directory is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
// REMOVE NON-EMPTY DIRECTORY
|
// REMOVE NON-EMPTY DIRECTORY
|
||||||
path = Deno.makeTempDirSync() + "/dir/subdir";
|
path = Deno.makeTempDirSync() + "/dir/subdir";
|
||||||
const subPath = path + "/subsubdir";
|
const subPath = path + "/subsubdir";
|
||||||
|
@ -430,8 +411,7 @@ testPerm(
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// Directory is gone
|
// Directory is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -454,8 +434,7 @@ testPerm(
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
// File is gone
|
// File is gone
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -468,8 +447,7 @@ testPerm({ write: true }, async function removeAllFail(): Promise<void> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testPerm({ write: false }, async function removeAllPerm(): Promise<void> {
|
testPerm({ write: false }, async function removeAllPerm(): Promise<void> {
|
||||||
|
@ -479,6 +457,6 @@ testPerm({ write: false }, async function removeAllPerm(): Promise<void> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,7 +17,7 @@ testPerm({ read: true, write: true }, function renameSyncSuccess(): void {
|
||||||
oldPathInfo = Deno.statSync(oldpath);
|
oldPathInfo = Deno.statSync(oldpath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtErr = true;
|
caughtErr = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
}
|
}
|
||||||
assert(caughtErr);
|
assert(caughtErr);
|
||||||
assertEquals(oldPathInfo, undefined);
|
assertEquals(oldPathInfo, undefined);
|
||||||
|
@ -32,7 +32,7 @@ testPerm({ read: false, write: true }, function renameSyncReadPerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ testPerm({ read: true, write: false }, function renameSyncWritePerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ testPerm({ read: true, write: true }, async function renameSuccess(): Promise<
|
||||||
oldPathInfo = Deno.statSync(oldpath);
|
oldPathInfo = Deno.statSync(oldpath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtErr = true;
|
caughtErr = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
}
|
}
|
||||||
assert(caughtErr);
|
assert(caughtErr);
|
||||||
assertEquals(oldPathInfo, undefined);
|
assertEquals(oldPathInfo, undefined);
|
||||||
|
|
|
@ -23,8 +23,7 @@ testPerm({ read: false }, async function statSyncPerm(): Promise<void> {
|
||||||
Deno.statSync("README.md");
|
Deno.statSync("README.md");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -37,8 +36,7 @@ testPerm({ read: true }, async function statSyncNotFound(): Promise<void> {
|
||||||
badInfo = Deno.statSync("bad_file_name");
|
badInfo = Deno.statSync("bad_file_name");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
|
@ -65,8 +63,7 @@ testPerm({ read: false }, async function lstatSyncPerm(): Promise<void> {
|
||||||
Deno.lstatSync("README.md");
|
Deno.lstatSync("README.md");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -79,8 +76,7 @@ testPerm({ read: true }, async function lstatSyncNotFound(): Promise<void> {
|
||||||
badInfo = Deno.lstatSync("bad_file_name");
|
badInfo = Deno.lstatSync("bad_file_name");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
|
@ -107,8 +103,7 @@ testPerm({ read: false }, async function statPerm(): Promise<void> {
|
||||||
await Deno.stat("README.md");
|
await Deno.stat("README.md");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -121,8 +116,7 @@ testPerm({ read: true }, async function statNotFound(): Promise<void> {
|
||||||
badInfo = await Deno.stat("bad_file_name");
|
badInfo = await Deno.stat("bad_file_name");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
|
@ -149,8 +143,7 @@ testPerm({ read: false }, async function lstatPerm(): Promise<void> {
|
||||||
await Deno.lstat("README.md");
|
await Deno.lstat("README.md");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -163,8 +156,7 @@ testPerm({ read: true }, async function lstatNotFound(): Promise<void> {
|
||||||
badInfo = await Deno.lstat("bad_file_name");
|
badInfo = await Deno.lstat("bad_file_name");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
// import { ReadableStreamDefaultReader } from "./readable-stream-default-reader.ts";
|
// import { ReadableStreamDefaultReader } from "./readable-stream-default-reader.ts";
|
||||||
// import { WritableStreamDefaultWriter } from "./writable-stream-default-writer.ts";
|
// import { WritableStreamDefaultWriter } from "./writable-stream-default-writer.ts";
|
||||||
// import { PipeOptions } from "../dom_types.ts";
|
// import { PipeOptions } from "../dom_types.ts";
|
||||||
// import { DenoError, ErrorKind } from "../errors.ts";
|
// import { Err } from "../errors.ts";
|
||||||
|
|
||||||
// // add a wrapper to handle falsy rejections
|
// // add a wrapper to handle falsy rejections
|
||||||
// interface ErrorWrapper {
|
// interface ErrorWrapper {
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
// abortAlgorithm = (): void => {
|
// abortAlgorithm = (): void => {
|
||||||
// // TODO this should be a DOMException,
|
// // TODO this should be a DOMException,
|
||||||
// // https://github.com/stardazed/sd-streams/blob/master/packages/streams/src/pipe-to.ts#L38
|
// // https://github.com/stardazed/sd-streams/blob/master/packages/streams/src/pipe-to.ts#L38
|
||||||
// const error = new DenoError(ErrorKind.AbortError, "Aborted");
|
// const error = new Err.Aborted("Aborted");
|
||||||
// const actions: Array<() => Promise<void>> = [];
|
// const actions: Array<() => Promise<void>> = [];
|
||||||
// if (preventAbort === false) {
|
// if (preventAbort === false) {
|
||||||
// actions.push(() => {
|
// actions.push(() => {
|
||||||
|
|
|
@ -15,7 +15,6 @@ testPerm({ read: true, write: true }, function symlinkSyncSuccess(): void {
|
||||||
}
|
}
|
||||||
if (errOnWindows) {
|
if (errOnWindows) {
|
||||||
assertEquals(Deno.build.os, "win");
|
assertEquals(Deno.build.os, "win");
|
||||||
assertEquals(errOnWindows.kind, Deno.ErrorKind.Other);
|
|
||||||
assertEquals(errOnWindows.message, "Not implemented");
|
assertEquals(errOnWindows.message, "Not implemented");
|
||||||
} else {
|
} else {
|
||||||
const newNameInfoLStat = Deno.lstatSync(newname);
|
const newNameInfoLStat = Deno.lstatSync(newname);
|
||||||
|
@ -32,7 +31,7 @@ test(function symlinkSyncPerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -69,7 +68,6 @@ testPerm({ read: true, write: true }, async function symlinkSuccess(): Promise<
|
||||||
errOnWindows = e;
|
errOnWindows = e;
|
||||||
}
|
}
|
||||||
if (errOnWindows) {
|
if (errOnWindows) {
|
||||||
assertEquals(errOnWindows.kind, Deno.ErrorKind.Other);
|
|
||||||
assertEquals(errOnWindows.message, "Not implemented");
|
assertEquals(errOnWindows.message, "Not implemented");
|
||||||
} else {
|
} else {
|
||||||
const newNameInfoLStat = Deno.lstatSync(newname);
|
const newNameInfoLStat = Deno.lstatSync(newname);
|
||||||
|
|
|
@ -27,7 +27,6 @@ import * as base64 from "./base64.ts";
|
||||||
import { decodeUtf8 } from "./decode_utf8.ts";
|
import { decodeUtf8 } from "./decode_utf8.ts";
|
||||||
import * as domTypes from "./dom_types.ts";
|
import * as domTypes from "./dom_types.ts";
|
||||||
import { encodeUtf8 } from "./encode_utf8.ts";
|
import { encodeUtf8 } from "./encode_utf8.ts";
|
||||||
import { DenoError, ErrorKind } from "./errors.ts";
|
|
||||||
|
|
||||||
const CONTINUE = null;
|
const CONTINUE = null;
|
||||||
const END_OF_STREAM = -1;
|
const END_OF_STREAM = -1;
|
||||||
|
@ -105,10 +104,7 @@ export function atob(s: string): string {
|
||||||
const rem = s.length % 4;
|
const rem = s.length % 4;
|
||||||
if (rem === 1 || /[^+/0-9A-Za-z]/.test(s)) {
|
if (rem === 1 || /[^+/0-9A-Za-z]/.test(s)) {
|
||||||
// TODO: throw `DOMException`
|
// TODO: throw `DOMException`
|
||||||
throw new DenoError(
|
throw new TypeError("The string to be decoded is not correctly encoded");
|
||||||
ErrorKind.InvalidInput,
|
|
||||||
"The string to be decoded is not correctly encoded"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// base64-js requires length exactly times of 4
|
// base64-js requires length exactly times of 4
|
||||||
|
@ -130,8 +126,7 @@ export function btoa(s: string): string {
|
||||||
for (let i = 0; i < s.length; i++) {
|
for (let i = 0; i < s.length; i++) {
|
||||||
const charCode = s[i].charCodeAt(0);
|
const charCode = s[i].charCodeAt(0);
|
||||||
if (charCode > 0xff) {
|
if (charCode > 0xff) {
|
||||||
throw new DenoError(
|
throw new TypeError(
|
||||||
ErrorKind.InvalidInput,
|
|
||||||
"The string to be encoded contains characters " +
|
"The string to be encoded contains characters " +
|
||||||
"outside of the Latin1 range."
|
"outside of the Latin1 range."
|
||||||
);
|
);
|
||||||
|
|
|
@ -59,7 +59,7 @@ test(function btoaFailed(): void {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assert(!!err);
|
assert(!!err);
|
||||||
assertEquals(err.name, "InvalidInput");
|
assert(err instanceof TypeError);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function textDecoder2(): void {
|
test(function textDecoder2(): void {
|
||||||
|
|
|
@ -13,7 +13,7 @@ test(async function connectTLSNoPerm(): Promise<void> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ test(async function connectTLSCertFileNoReadPerm(): Promise<void> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -51,8 +51,7 @@ testPerm(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Deno.listenTLS({
|
Deno.listenTLS({
|
||||||
|
@ -62,8 +61,7 @@ testPerm(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.NotFound);
|
assert(err instanceof Deno.Err.NotFound);
|
||||||
assertEquals(err.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -79,7 +77,7 @@ testPerm({ net: true }, async function listenTLSNoReadPerm(): Promise<void> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -108,8 +106,7 @@ testPerm(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.Other);
|
assert(err instanceof Error);
|
||||||
assertEquals(err.name, "Other");
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -138,8 +135,7 @@ testPerm(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.Other);
|
assert(err instanceof Error);
|
||||||
assertEquals(err.name, "Other");
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { testPerm, assertEquals } from "./test_util.ts";
|
import { testPerm, assertEquals, assert } from "./test_util.ts";
|
||||||
|
|
||||||
function readDataSync(name: string): string {
|
function readDataSync(name: string): string {
|
||||||
const data = Deno.readFileSync(name);
|
const data = Deno.readFileSync(name);
|
||||||
|
@ -58,7 +58,7 @@ testPerm({ write: false }, function truncateSyncPerm(): void {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -69,6 +69,6 @@ testPerm({ write: false }, async function truncatePerm(): Promise<void> {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(err.name, "PermissionDenied");
|
assertEquals(err.name, "PermissionDenied");
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { testPerm, assert, assertEquals } from "./test_util.ts";
|
import { testPerm, assert } from "./test_util.ts";
|
||||||
|
|
||||||
// Allow 10 second difference.
|
// Allow 10 second difference.
|
||||||
// Note this might not be enough for FAT (but we are not testing on such fs).
|
// Note this might not be enough for FAT (but we are not testing on such fs).
|
||||||
|
@ -78,8 +78,7 @@ testPerm({ read: true, write: true }, function utimeSyncNotFound(): void {
|
||||||
Deno.utimeSync("/baddir", atime, mtime);
|
Deno.utimeSync("/baddir", atime, mtime);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
assertEquals(e.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -93,8 +92,7 @@ testPerm({ read: true, write: false }, function utimeSyncPerm(): void {
|
||||||
Deno.utimeSync("/some_dir", atime, mtime);
|
Deno.utimeSync("/some_dir", atime, mtime);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -159,8 +157,7 @@ testPerm({ read: true, write: true }, async function utimeNotFound(): Promise<
|
||||||
await Deno.utime("/baddir", atime, mtime);
|
await Deno.utime("/baddir", atime, mtime);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
assertEquals(e.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -176,8 +173,7 @@ testPerm({ read: true, write: false }, async function utimeSyncPerm(): Promise<
|
||||||
await Deno.utime("/some_dir", atime, mtime);
|
await Deno.utime("/some_dir", atime, mtime);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,8 +22,7 @@ testPerm({ write: true }, function writeFileSyncFail(): void {
|
||||||
Deno.writeFileSync(filename, data);
|
Deno.writeFileSync(filename, data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
assertEquals(e.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -38,8 +37,7 @@ testPerm({ write: false }, function writeFileSyncPerm(): void {
|
||||||
Deno.writeFileSync(filename, data);
|
Deno.writeFileSync(filename, data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -66,8 +64,7 @@ testPerm({ read: true, write: true }, function writeFileSyncCreate(): void {
|
||||||
Deno.writeFileSync(filename, data, { create: false });
|
Deno.writeFileSync(filename, data, { create: false });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
assertEquals(e.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
|
|
||||||
|
@ -128,8 +125,7 @@ testPerm(
|
||||||
await Deno.writeFile(filename, data);
|
await Deno.writeFile(filename, data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
assertEquals(e.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
}
|
}
|
||||||
|
@ -147,8 +143,7 @@ testPerm({ read: true, write: false }, async function writeFilePerm(): Promise<
|
||||||
await Deno.writeFile(filename, data);
|
await Deno.writeFile(filename, data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
|
assert(e instanceof Deno.Err.PermissionDenied);
|
||||||
assertEquals(e.name, "PermissionDenied");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
@ -180,8 +175,7 @@ testPerm({ read: true, write: true }, async function writeFileCreate(): Promise<
|
||||||
await Deno.writeFile(filename, data, { create: false });
|
await Deno.writeFile(filename, data, { create: false });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
caughtError = true;
|
caughtError = true;
|
||||||
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
assert(e instanceof Deno.Err.NotFound);
|
||||||
assertEquals(e.name, "NotFound");
|
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
|
|
||||||
|
|
36
cli/msg.rs
36
cli/msg.rs
|
@ -1,41 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
// Warning! The values in this enum are duplicated in js/errors.ts
|
|
||||||
// Update carefully!
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#[repr(i8)]
|
|
||||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
|
||||||
pub enum ErrorKind {
|
|
||||||
NotFound = 1,
|
|
||||||
PermissionDenied = 2,
|
|
||||||
ConnectionRefused = 3,
|
|
||||||
ConnectionReset = 4,
|
|
||||||
ConnectionAborted = 5,
|
|
||||||
NotConnected = 6,
|
|
||||||
AddrInUse = 7,
|
|
||||||
AddrNotAvailable = 8,
|
|
||||||
BrokenPipe = 9,
|
|
||||||
AlreadyExists = 10,
|
|
||||||
WouldBlock = 11,
|
|
||||||
InvalidInput = 12,
|
|
||||||
InvalidData = 13,
|
|
||||||
TimedOut = 14,
|
|
||||||
Interrupted = 15,
|
|
||||||
WriteZero = 16,
|
|
||||||
Other = 17,
|
|
||||||
UnexpectedEof = 18,
|
|
||||||
BadResource = 19,
|
|
||||||
UrlParse = 20,
|
|
||||||
Http = 21,
|
|
||||||
TooLarge = 22,
|
|
||||||
InvalidSeekMode = 23,
|
|
||||||
UnixError = 24,
|
|
||||||
InvalidPath = 25,
|
|
||||||
ImportPrefixMissing = 26,
|
|
||||||
Diagnostic = 27,
|
|
||||||
JSError = 28,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warning! The values in this enum are duplicated in js/compiler.ts
|
// Warning! The values in this enum are duplicated in js/compiler.ts
|
||||||
// Update carefully!
|
// Update carefully!
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
//! alternative to flatbuffers using a very simple list of int32s to lay out
|
//! alternative to flatbuffers using a very simple list of int32s to lay out
|
||||||
//! messages. The first i32 is used to determine if a message a flatbuffer
|
//! messages. The first i32 is used to determine if a message a flatbuffer
|
||||||
//! message or a "minimal" message.
|
//! message or a "minimal" message.
|
||||||
|
use crate::deno_error::ErrorKind;
|
||||||
use crate::deno_error::GetErrorKind;
|
use crate::deno_error::GetErrorKind;
|
||||||
use crate::msg::ErrorKind;
|
|
||||||
use byteorder::{LittleEndian, WriteBytesExt};
|
use byteorder::{LittleEndian, WriteBytesExt};
|
||||||
use deno_core::Buf;
|
use deno_core::Buf;
|
||||||
use deno_core::CoreOp;
|
use deno_core::CoreOp;
|
||||||
|
@ -124,7 +124,7 @@ where
|
||||||
let error_record = ErrorRecord {
|
let error_record = ErrorRecord {
|
||||||
promise_id: 0,
|
promise_id: 0,
|
||||||
arg: -1,
|
arg: -1,
|
||||||
error_code: ErrorKind::InvalidInput as i32,
|
error_code: ErrorKind::TypeError as i32,
|
||||||
error_message: "Unparsable control buffer"
|
error_message: "Unparsable control buffer"
|
||||||
.to_string()
|
.to_string()
|
||||||
.as_bytes()
|
.as_bytes()
|
||||||
|
|
|
@ -190,7 +190,7 @@ fn op_seek(
|
||||||
2 => SeekFrom::End(i64::from(offset)),
|
2 => SeekFrom::End(i64::from(offset)),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(ErrBox::from(DenoError::new(
|
return Err(ErrBox::from(DenoError::new(
|
||||||
ErrorKind::InvalidSeekMode,
|
ErrorKind::TypeError,
|
||||||
format!("Invalid seek mode: {}", whence),
|
format!("Invalid seek mode: {}", whence),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
use super::dispatch_json::{Deserialize, JsonOp, Value};
|
use super::dispatch_json::{Deserialize, JsonOp, Value};
|
||||||
use crate::deno_error::DenoError;
|
use crate::deno_error::DenoError;
|
||||||
use crate::deno_error::ErrorKind;
|
use crate::deno_error::ErrorKind;
|
||||||
use crate::deno_error::GetErrorKind;
|
|
||||||
use crate::fmt_errors::JSError;
|
use crate::fmt_errors::JSError;
|
||||||
use crate::futures::SinkExt;
|
use crate::futures::SinkExt;
|
||||||
use crate::global_state::GlobalState;
|
use crate::global_state::GlobalState;
|
||||||
|
@ -212,11 +211,17 @@ fn op_host_terminate_worker(
|
||||||
fn serialize_worker_event(event: WorkerEvent) -> Value {
|
fn serialize_worker_event(event: WorkerEvent) -> Value {
|
||||||
match event {
|
match event {
|
||||||
WorkerEvent::Message(buf) => json!({ "type": "msg", "data": buf }),
|
WorkerEvent::Message(buf) => json!({ "type": "msg", "data": buf }),
|
||||||
WorkerEvent::Error(error) => match error.kind() {
|
WorkerEvent::Error(error) => {
|
||||||
ErrorKind::JSError => {
|
let mut serialized_error = json!({
|
||||||
let error = error.downcast::<JSError>().unwrap();
|
"type": "error",
|
||||||
let exception: V8Exception = error.into();
|
"error": {
|
||||||
json!({
|
"message": error.to_string(),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Ok(err) = error.downcast::<JSError>() {
|
||||||
|
let exception: V8Exception = err.into();
|
||||||
|
serialized_error = json!({
|
||||||
"type": "error",
|
"type": "error",
|
||||||
"error": {
|
"error": {
|
||||||
"message": exception.message,
|
"message": exception.message,
|
||||||
|
@ -224,15 +229,11 @@ fn serialize_worker_event(event: WorkerEvent) -> Value {
|
||||||
"lineNumber": exception.line_number,
|
"lineNumber": exception.line_number,
|
||||||
"columnNumber": exception.start_column,
|
"columnNumber": exception.start_column,
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
_ => json!({
|
|
||||||
"type": "error",
|
serialized_error
|
||||||
"error": {
|
}
|
||||||
"message": error.to_string(),
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
[WILDCARD]
|
[WILDCARD]
|
||||||
error: Uncaught BadResource: bad resource id
|
error: Uncaught BadResource: bad resource id
|
||||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
[WILDCARD]errors.ts:[WILDCARD]
|
||||||
at DenoError ([WILDCARD]errors.ts:[WILDCARD])
|
at BadResource ([WILDCARD]errors.ts:[WILDCARD])
|
||||||
|
at constructError ([WILDCARD]errors.ts:[WILDCARD])
|
||||||
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
||||||
at sendAsync ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
at sendAsync ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts" from "[WILDCARD]/error_004_missing_module.ts"
|
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts" from "[WILDCARD]/error_004_missing_module.ts"
|
||||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
[WILDCARD]errors.ts:[WILDCARD]
|
||||||
at DenoError ([WILDCARD]errors.ts:[WILDCARD])
|
at NotFound ([WILDCARD]errors.ts:[WILDCARD])
|
||||||
|
at constructError ([WILDCARD]errors.ts:[WILDCARD])
|
||||||
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
||||||
at sendAsync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
at sendAsync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts" from "[WILDCARD]/error_005_missing_dynamic_import.ts"
|
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts" from "[WILDCARD]/error_005_missing_dynamic_import.ts"
|
||||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
[WILDCARD]errors.ts:[WILDCARD]
|
||||||
at DenoError ([WILDCARD]errors.ts:[WILDCARD])
|
at NotFound ([WILDCARD]errors.ts:[WILDCARD])
|
||||||
|
at constructError ([WILDCARD]errors.ts:[WILDCARD])
|
||||||
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
||||||
at sendAsync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
at sendAsync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/non-existent" from "[WILDCARD]/error_006_import_ext_failure.ts"
|
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/non-existent" from "[WILDCARD]/error_006_import_ext_failure.ts"
|
||||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
[WILDCARD]errors.ts:[WILDCARD]
|
||||||
at DenoError ([WILDCARD]errors.ts:[WILDCARD])
|
at NotFound ([WILDCARD]errors.ts:[WILDCARD])
|
||||||
|
at constructError ([WILDCARD]errors.ts:[WILDCARD])
|
||||||
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
||||||
at sendAsync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
at sendAsync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_011_bad_module_specifier.ts"
|
[WILDCARD]error: Uncaught URIError: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_011_bad_module_specifier.ts"
|
||||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
[WILDCARD]errors.ts:[WILDCARD]
|
||||||
at DenoError ($deno$/errors.ts:[WILDCARD])
|
at constructError ($deno$/errors.ts:[WILDCARD])
|
||||||
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
|
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
|
||||||
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
|
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
|
||||||
at resolveModules ($deno$/compiler_imports.ts:[WILDCARD])
|
at resolveModules ($deno$/compiler_imports.ts:[WILDCARD])
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts"
|
[WILDCARD]error: Uncaught URIError: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts"
|
||||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
[WILDCARD]errors.ts:[WILDCARD]
|
||||||
at DenoError ($deno$/errors.ts:[WILDCARD])
|
at constructError ($deno$/errors.ts:[WILDCARD])
|
||||||
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
|
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
|
||||||
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
|
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
|
||||||
at resolveModules ($deno$/compiler_imports.ts:[WILDCARD])
|
at resolveModules ($deno$/compiler_imports.ts:[WILDCARD])
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "baz" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/type_definitions/bar.d.ts"
|
[WILDCARD]error: Uncaught URIError: relative import path "baz" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/type_definitions/bar.d.ts"
|
||||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
[WILDCARD]errors.ts:[WILDCARD]
|
||||||
at DenoError ($deno$/errors.ts:[WILDCARD])
|
at constructError ($deno$/errors.ts:[WILDCARD])
|
||||||
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
|
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
|
||||||
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
|
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
|
||||||
at resolveModules ($deno$/compiler_imports.ts:[WILDCARD])
|
at resolveModules ($deno$/compiler_imports.ts:[WILDCARD])
|
||||||
|
|
|
@ -5,14 +5,12 @@
|
||||||
|
|
||||||
import { Mark } from "./mark.ts";
|
import { Mark } from "./mark.ts";
|
||||||
|
|
||||||
const { DenoError, ErrorKind } = Deno;
|
export class YAMLError extends Error {
|
||||||
|
|
||||||
export class YAMLError extends DenoError<typeof ErrorKind.Other> {
|
|
||||||
constructor(
|
constructor(
|
||||||
message = "(unknown reason)",
|
message = "(unknown reason)",
|
||||||
protected mark: Mark | string = ""
|
protected mark: Mark | string = ""
|
||||||
) {
|
) {
|
||||||
super(ErrorKind.Other, `${message} ${mark}`);
|
super(`${message} ${mark}`);
|
||||||
this.name = this.constructor.name;
|
this.name = this.constructor.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ async function ensureValidCopy(
|
||||||
try {
|
try {
|
||||||
destStat = await Deno.lstat(dest);
|
destStat = await Deno.lstat(dest);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof Deno.DenoError && err.kind == Deno.ErrorKind.NotFound) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -57,7 +57,7 @@ function ensureValidCopySync(
|
||||||
try {
|
try {
|
||||||
destStat = Deno.lstatSync(dest);
|
destStat = Deno.lstatSync(dest);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof Deno.DenoError && err.kind == Deno.ErrorKind.NotFound) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { join } from "../path/mod.ts";
|
import { join } from "../path/mod.ts";
|
||||||
const {
|
const { readDir, readDirSync, mkdir, mkdirSync, remove, removeSync } = Deno;
|
||||||
readDir,
|
|
||||||
readDirSync,
|
|
||||||
mkdir,
|
|
||||||
mkdirSync,
|
|
||||||
remove,
|
|
||||||
removeSync,
|
|
||||||
ErrorKind
|
|
||||||
} = Deno;
|
|
||||||
/**
|
/**
|
||||||
* Ensures that a directory is empty.
|
* Ensures that a directory is empty.
|
||||||
* Deletes directory contents if the directory is not empty.
|
* Deletes directory contents if the directory is not empty.
|
||||||
|
@ -28,7 +20,7 @@ export async function emptyDir(dir: string): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if ((err as Deno.DenoError<Deno.ErrorKind>).kind !== ErrorKind.NotFound) {
|
if (!(err instanceof Deno.Err.NotFound)) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +49,7 @@ export function emptyDirSync(dir: string): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if ((err as Deno.DenoError<Deno.ErrorKind>).kind !== ErrorKind.NotFound) {
|
if (!(err instanceof Deno.Err.NotFound)) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// if not exist. then create it
|
// if not exist. then create it
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { getFileInfoType } from "./utils.ts";
|
import { getFileInfoType } from "./utils.ts";
|
||||||
const { lstat, lstatSync, mkdir, mkdirSync, ErrorKind } = Deno;
|
const { lstat, lstatSync, mkdir, mkdirSync } = Deno;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the directory exists.
|
* Ensures that the directory exists.
|
||||||
|
@ -16,7 +16,7 @@ export async function ensureDir(dir: string): Promise<void> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof Deno.DenoError && err.kind === ErrorKind.NotFound) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
// if dir not exists. then create it.
|
// if dir not exists. then create it.
|
||||||
await mkdir(dir, { recursive: true });
|
await mkdir(dir, { recursive: true });
|
||||||
return;
|
return;
|
||||||
|
@ -39,7 +39,7 @@ export function ensureDirSync(dir: string): void {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof Deno.DenoError && err.kind == ErrorKind.NotFound) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
// if dir not exists. then create it.
|
// if dir not exists. then create it.
|
||||||
mkdirSync(dir, { recursive: true });
|
mkdirSync(dir, { recursive: true });
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import * as path from "../path/mod.ts";
|
import * as path from "../path/mod.ts";
|
||||||
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
|
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
|
||||||
import { getFileInfoType } from "./utils.ts";
|
import { getFileInfoType } from "./utils.ts";
|
||||||
const { lstat, lstatSync, writeFile, writeFileSync, ErrorKind } = Deno;
|
const { lstat, lstatSync, writeFile, writeFileSync } = Deno;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the file exists.
|
* Ensures that the file exists.
|
||||||
|
@ -23,7 +23,7 @@ export async function ensureFile(filePath: string): Promise<void> {
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// if file not exists
|
// if file not exists
|
||||||
if (err instanceof Deno.DenoError && err.kind === ErrorKind.NotFound) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
// ensure dir exists
|
// ensure dir exists
|
||||||
await ensureDir(path.dirname(filePath));
|
await ensureDir(path.dirname(filePath));
|
||||||
// create file
|
// create file
|
||||||
|
@ -54,7 +54,7 @@ export function ensureFileSync(filePath: string): void {
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// if file not exists
|
// if file not exists
|
||||||
if (err instanceof Deno.DenoError && err.kind === ErrorKind.NotFound) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
// ensure dir exists
|
// ensure dir exists
|
||||||
ensureDirSync(path.dirname(filePath));
|
ensureDirSync(path.dirname(filePath));
|
||||||
// create file
|
// create file
|
||||||
|
|
|
@ -143,8 +143,7 @@ Deno.test(async function ensureLinkDirectoryIfItExist(): Promise<void> {
|
||||||
await assertThrowsAsync(
|
await assertThrowsAsync(
|
||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
await ensureLink(testDir, linkDir);
|
await ensureLink(testDir, linkDir);
|
||||||
},
|
}
|
||||||
Deno.DenoError
|
|
||||||
// "Operation not permitted (os error 1)" // throw an local matching test
|
// "Operation not permitted (os error 1)" // throw an local matching test
|
||||||
// "Access is denied. (os error 5)" // throw in CI
|
// "Access is denied. (os error 5)" // throw in CI
|
||||||
);
|
);
|
||||||
|
@ -163,8 +162,7 @@ Deno.test(function ensureLinkSyncDirectoryIfItExist(): void {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
(): void => {
|
(): void => {
|
||||||
ensureLinkSync(testDir, linkDir);
|
ensureLinkSync(testDir, linkDir);
|
||||||
},
|
}
|
||||||
Deno.DenoError
|
|
||||||
// "Operation not permitted (os error 1)" // throw an local matching test
|
// "Operation not permitted (os error 1)" // throw an local matching test
|
||||||
// "Access is denied. (os error 5)" // throw in CI
|
// "Access is denied. (os error 5)" // throw in CI
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
const { lstat, lstatSync, DenoError, ErrorKind } = Deno;
|
const { lstat, lstatSync } = Deno;
|
||||||
/**
|
/**
|
||||||
* Test whether or not the given path exists by checking with the file system
|
* Test whether or not the given path exists by checking with the file system
|
||||||
*/
|
*/
|
||||||
|
@ -7,10 +7,8 @@ export async function exists(filePath: string): Promise<boolean> {
|
||||||
return lstat(filePath)
|
return lstat(filePath)
|
||||||
.then((): boolean => true)
|
.then((): boolean => true)
|
||||||
.catch((err: Error): boolean => {
|
.catch((err: Error): boolean => {
|
||||||
if (err instanceof DenoError) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
if (err.kind === ErrorKind.NotFound) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -25,10 +23,8 @@ export function existsSync(filePath: string): boolean {
|
||||||
lstatSync(filePath);
|
lstatSync(filePath);
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof DenoError) {
|
if (err instanceof Deno.Err.NotFound) {
|
||||||
if (err.kind === ErrorKind.NotFound) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,7 @@ import {
|
||||||
} from "../path/mod.ts";
|
} from "../path/mod.ts";
|
||||||
import { WalkInfo, walk, walkSync } from "./walk.ts";
|
import { WalkInfo, walk, walkSync } from "./walk.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../testing/asserts.ts";
|
||||||
const { ErrorKind, cwd, stat, statSync } = Deno;
|
const { cwd, stat, statSync } = Deno;
|
||||||
type ErrorKind = Deno.ErrorKind;
|
|
||||||
type DenoError = Deno.DenoError<ErrorKind>;
|
|
||||||
type FileInfo = Deno.FileInfo;
|
type FileInfo = Deno.FileInfo;
|
||||||
|
|
||||||
export interface ExpandGlobOptions extends GlobOptions {
|
export interface ExpandGlobOptions extends GlobOptions {
|
||||||
|
@ -45,7 +43,7 @@ function split(path: string): SplitPath {
|
||||||
}
|
}
|
||||||
|
|
||||||
function throwUnlessNotFound(error: Error): void {
|
function throwUnlessNotFound(error: Error): void {
|
||||||
if ((error as DenoError).kind != ErrorKind.NotFound) {
|
if (!(error instanceof Deno.Err.NotFound)) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
const { DenoError, ErrorKind, cwd, chdir, makeTempDir, mkdir, open } = Deno;
|
const { cwd, chdir, makeTempDir, mkdir, open } = Deno;
|
||||||
const { remove } = Deno;
|
const { remove } = Deno;
|
||||||
type ErrorKind = Deno.ErrorKind;
|
|
||||||
type DenoError = Deno.DenoError<ErrorKind>;
|
|
||||||
import { walk, walkSync, WalkOptions, WalkInfo } from "./walk.ts";
|
import { walk, walkSync, WalkOptions, WalkInfo } from "./walk.ts";
|
||||||
import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
|
import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
|
||||||
|
|
||||||
|
@ -235,10 +233,9 @@ testWalk(
|
||||||
testWalk(
|
testWalk(
|
||||||
async (_d: string): Promise<void> => {},
|
async (_d: string): Promise<void> => {},
|
||||||
async function nonexistentRoot(): Promise<void> {
|
async function nonexistentRoot(): Promise<void> {
|
||||||
const error = (await assertThrowsAsync(async () => {
|
await assertThrowsAsync(async () => {
|
||||||
await walkArray("nonexistent");
|
await walkArray("nonexistent");
|
||||||
}, DenoError)) as DenoError;
|
}, Deno.Err.NotFound);
|
||||||
assertEquals(error.kind, ErrorKind.NotFound);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
// TODO Add tests like these:
|
// TODO Add tests like these:
|
||||||
// https://github.com/indexzero/http-server/blob/master/test/http-server-test.js
|
// https://github.com/indexzero/http-server/blob/master/test/http-server-test.js
|
||||||
|
|
||||||
const { ErrorKind, DenoError, args, stat, readDir, open, exit } = Deno;
|
const { args, stat, readDir, open, exit } = Deno;
|
||||||
import { posix } from "../path/mod.ts";
|
import { posix } from "../path/mod.ts";
|
||||||
import {
|
import {
|
||||||
listenAndServe,
|
listenAndServe,
|
||||||
|
@ -163,7 +163,7 @@ async function serveDir(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function serveFallback(req: ServerRequest, e: Error): Promise<Response> {
|
async function serveFallback(req: ServerRequest, e: Error): Promise<Response> {
|
||||||
if (e instanceof DenoError && e.kind === ErrorKind.NotFound) {
|
if (e instanceof Deno.Err.NotFound) {
|
||||||
return {
|
return {
|
||||||
status: 404,
|
status: 404,
|
||||||
body: encoder.encode("Not found")
|
body: encoder.encode("Not found")
|
||||||
|
|
|
@ -57,7 +57,7 @@ function stat(filename: string): StatResult {
|
||||||
if (statCache !== null) statCache.set(filename, result);
|
if (statCache !== null) statCache.set(filename, result);
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.kind === Deno.ErrorKind.PermissionDenied) {
|
if (e instanceof Deno.Err.PermissionDenied) {
|
||||||
throw new Error("CJS loader requires --allow-read.");
|
throw new Error("CJS loader requires --allow-read.");
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -24,13 +24,11 @@ test({
|
||||||
() => {
|
() => {
|
||||||
process.chdir("non-existent-directory-name");
|
process.chdir("non-existent-directory-name");
|
||||||
},
|
},
|
||||||
Deno.DenoError,
|
Deno.Err.NotFound,
|
||||||
"file"
|
"file"
|
||||||
// On every OS Deno returns: "No such file" except for Windows, where it's:
|
// On every OS Deno returns: "No such file" except for Windows, where it's:
|
||||||
// "The system cannot find the file specified. (os error 2)" so "file" is
|
// "The system cannot find the file specified. (os error 2)" so "file" is
|
||||||
// the only common string here.
|
// the only common string here.
|
||||||
// TODO(rsp): Crazy idea: 404 for things like this?
|
|
||||||
// It would be nice to have error codes like 404 or 403 in addition to strings.
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,8 +3,6 @@ import { globrex } from "./globrex.ts";
|
||||||
import { join, normalize } from "./mod.ts";
|
import { join, normalize } from "./mod.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../testing/asserts.ts";
|
||||||
|
|
||||||
const { DenoError, ErrorKind } = Deno;
|
|
||||||
|
|
||||||
export interface GlobOptions {
|
export interface GlobOptions {
|
||||||
extended?: boolean;
|
extended?: boolean;
|
||||||
globstar?: boolean;
|
globstar?: boolean;
|
||||||
|
@ -91,10 +89,7 @@ export function normalizeGlob(
|
||||||
{ globstar = false }: GlobOptions = {}
|
{ globstar = false }: GlobOptions = {}
|
||||||
): string {
|
): string {
|
||||||
if (!!glob.match(/\0/g)) {
|
if (!!glob.match(/\0/g)) {
|
||||||
throw new DenoError(
|
throw new Error(`Glob contains invalid characters: "${glob}"`);
|
||||||
ErrorKind.InvalidPath,
|
|
||||||
`Glob contains invalid characters: "${glob}"`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (!globstar) {
|
if (!globstar) {
|
||||||
return normalize(glob);
|
return normalize(glob);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import { parse } from "../flags/mod.ts";
|
import { parse } from "../flags/mod.ts";
|
||||||
import { ExpandGlobOptions, expandGlob } from "../fs/mod.ts";
|
import { ExpandGlobOptions, expandGlob } from "../fs/mod.ts";
|
||||||
import { isWindows, join } from "../path/mod.ts";
|
import { isWindows, join } from "../path/mod.ts";
|
||||||
const { DenoError, ErrorKind, args, cwd, exit } = Deno;
|
const { args, cwd, exit } = Deno;
|
||||||
|
|
||||||
const DIR_GLOBS = [join("**", "?(*_)test.{js,ts}")];
|
const DIR_GLOBS = [join("**", "?(*_)test.{js,ts}")];
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ export async function runTestModules({
|
||||||
if (moduleCount == 0) {
|
if (moduleCount == 0) {
|
||||||
const noneFoundMessage = "No matching test modules found.";
|
const noneFoundMessage = "No matching test modules found.";
|
||||||
if (!allowNone) {
|
if (!allowNone) {
|
||||||
throw new DenoError(ErrorKind.NotFound, noneFoundMessage);
|
throw new Deno.Err.NotFound(noneFoundMessage);
|
||||||
} else if (!disableLog) {
|
} else if (!disableLog) {
|
||||||
console.log(noneFoundMessage);
|
console.log(noneFoundMessage);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue