Skip to content

Commit

Permalink
non global error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ksjogo committed Dec 26, 2021
1 parent 4bb7384 commit a43f2d2
Show file tree
Hide file tree
Showing 17 changed files with 284 additions and 262 deletions.
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"type": "pwa-node",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": ["${workspaceFolder}/js/**/*.js"]
},
{
"name": "Launch Test",
"program": "${workspaceFolder}/js/tests/test.js",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"type": "pwa-node",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": ["${workspaceFolder}/js/**/*.js"]
}
]
}
112 changes: 0 additions & 112 deletions errors.ts

This file was deleted.

5 changes: 2 additions & 3 deletions parse_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as utils from "tsutils"
import ts, { SyntaxKind, tokenToString } from "typescript"

import { AssetSourceFile } from "./project/assets/asset_source_file"
import { ErrorName, TsGdError, addError } from "./errors"
import TsGdProject, { ErrorName } from "./project"
import { LibraryFunctionName } from "./parse_node/library_functions"
import { Scope } from "./scope"
import {
Expand Down Expand Up @@ -63,7 +63,6 @@ import { parseVariableDeclarationList } from "./parse_node/parse_variable_declar
import { parseVariableStatement } from "./parse_node/parse_variable_statement"
import { parseWhileStatement } from "./parse_node/parse_while_statement"
import { parseYieldExpression } from "./parse_node/parse_yield_expression"
import TsGdProject from "./project"

export type ParseState = {
isConstructor: boolean
Expand Down Expand Up @@ -483,7 +482,7 @@ export const parseNode = (

default:
console.error("Unknown token:", syntaxKindToString(genericNode.kind))
addError({
props.project.errors.add({
error: ErrorName.UnknownTsSyntax,
location: genericNode,
stack: new Error().stack ?? "",
Expand Down
6 changes: 3 additions & 3 deletions parse_node/parse_arrow_function.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts, { SyntaxKind } from "typescript"

import { ErrorName, addError } from "../errors"
import { ErrorName } from "../project/errors"
import { ParseNodeType, ParseState, combine } from "../parse_node"

/**
Expand Down Expand Up @@ -38,7 +38,7 @@ const getFreeVariables = (

if (symbol) {
if (!symbol.declarations) {
addError({
props.project.errors.add({
error: ErrorName.DeclarationNotGiven,
location: node,
stack: new Error().stack ?? "",
Expand Down Expand Up @@ -183,7 +183,7 @@ ${unwrapCapturedScope}
.symbol?.declarations

if (!decls) {
addError({
props.project.errors.add({
error: ErrorName.DeclarationNotGiven,
location: node,
stack: new Error().stack ?? "",
Expand Down
8 changes: 4 additions & 4 deletions parse_node/parse_call_expression.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts, { SyntaxKind } from "typescript"

import { ErrorName, addError } from "../errors"
import { ErrorName } from "../project/errors"
import {
ExtraLine,
ExtraLineType,
Expand Down Expand Up @@ -202,7 +202,7 @@ export const parseCallExpression = (
}

if (!parsedArgs[0]) {
addError({
props.project.errors.add({
description:
"Missing arrow function argument in signal connect invocation.",
error: ErrorName.Ts2GdError,
Expand All @@ -217,7 +217,7 @@ export const parseCallExpression = (
)

if (!arrowFunctionObj) {
addError({
props.project.errors.add({
description:
"ts2gd can't find that arrow function. This is an internal ts2gd error. Please report it on GitHub along with the code that caused it.",
error: ErrorName.Ts2GdError,
Expand Down Expand Up @@ -294,7 +294,7 @@ export const parseCallExpression = (
content: expressionWithoutRpcName,
}
} else {
addError({
props.project.errors.add({
description: "I'm confused by this rpc",
error: ErrorName.Ts2GdError,
location: pae.expression,
Expand Down
4 changes: 2 additions & 2 deletions parse_node/parse_class_declaration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts, { SyntaxKind } from "typescript"

import { ErrorName, addError } from "../errors"
import { ErrorName } from "../project/errors"
import { ParseNodeType, ParseState, combine } from "../parse_node"
import { Test } from "../tests/test"
import { getGodotType } from "../ts_utils"
Expand Down Expand Up @@ -91,7 +91,7 @@ export const parseClassDeclaration = (
)

if (!modifiers?.includes("export") && !isAutoload) {
addError({
props.project.errors.add({
description: "You must export this class.",
error: ErrorName.ClassMustBeExported,
location: node,
Expand Down
4 changes: 2 additions & 2 deletions parse_node/parse_import_declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UsageDomain } from "tsutils"
import ts, { SyntaxKind } from "typescript"

import TsGdProject from "../project/project"
import { ErrorName, addError } from "../errors"
import { ErrorName } from "../project/errors"
import { ParseNodeType, ParseState, combine } from "../parse_node"
import { isEnumType } from "../ts_utils"

Expand Down Expand Up @@ -152,7 +152,7 @@ export const parseImportDeclaration = (
continue
}

addError({
props.project.errors.add({
error: ErrorName.InvalidNumber,
location: node,
description: `Import ${pathToImportedTs} not found.`,
Expand Down
8 changes: 4 additions & 4 deletions parse_node/parse_property_declaration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from "chalk"
import ts, { SyntaxKind } from "typescript"

import { ErrorName, addError } from "../errors"
import { ErrorName } from "../project/errors"
import { ParseNodeType, ParseState, combine } from "../parse_node"
import { Test } from "../tests/test"
import { getGodotType, getTypeHierarchy, isEnumType } from "../ts_utils"
Expand Down Expand Up @@ -127,7 +127,7 @@ const parseExportsArrayElement = (
if (typeGodotElement) {
godotExportArgs.push(typeGodotElement)
} else {
addError({
props.project.errors.add({
description: `
Cannot infer element type for array export.
`,
Expand Down Expand Up @@ -166,7 +166,7 @@ export const parseExportFlags = (
)

if (!decoration || decoration.expression.kind !== SyntaxKind.CallExpression) {
addError({
props.project.errors.add({
description: `
I'm confused by export_flags here. It should be a function call.
Expand Down Expand Up @@ -266,7 +266,7 @@ export const parsePropertyDeclaration = (
if (signalName.startsWith("$")) {
signalName = signalName.slice(1)
} else {
addError({
props.project.errors.add({
description: "Signals must be prefixed with $.",
error: ErrorName.SignalsMustBePrefixedWith$,
location: node,
Expand Down
6 changes: 3 additions & 3 deletions parse_node/parse_source_file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts, { SyntaxKind } from "typescript"

import { ErrorName, addError } from "../errors"
import { ErrorName } from "../project/errors"
import { ParseNodeType, ParseState, combine, parseNode } from "../parse_node"
import { Test } from "../tests/test"

Expand Down Expand Up @@ -62,7 +62,7 @@ export const parseSourceFile = (
) as ts.ClassDeclaration[]

if (allClasses.length === 0) {
addError({
props.project.errors.add({
error: ErrorName.ClassNameNotFound,
location: node,
description:
Expand Down Expand Up @@ -111,7 +111,7 @@ export const parseSourceFile = (
const className = classDecl.name?.text

if (!className) {
addError({
props.project.errors.add({
description: "Anonymous classes are not supported",
error: ErrorName.ClassCannotBeAnonymous,
location: classDecl,
Expand Down
10 changes: 5 additions & 5 deletions project/assets/asset_godot_scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "path"

import chalk from "chalk"

import { ErrorName, addError } from "../../errors"
import { ErrorName } from "../errors"
import TsGdProject from "../project"
import { parseGodotConfigFile } from "../godot_parser"

Expand Down Expand Up @@ -180,7 +180,7 @@ export class GodotNode {
}

if (this.isInstanceOverride()) {
addError({
this.project.errors.add({
description: `Error: should never try to get the type of an instance override. This is a ts2gd internal bug. Please report it on GitHub.`,
error: ErrorName.InvalidFile,
location: this.name,
Expand All @@ -196,7 +196,7 @@ export class GodotNode {
return instancedSceneType
}

addError({
this.project.errors.add({
description: `Error: Your Godot scene ${chalk.blue(
this.scene.fsPath
)} refers to ${chalk.red(
Expand Down Expand Up @@ -315,7 +315,7 @@ export class AssetGodotScene extends BaseAsset {
.find((sf) => sf.resPath === rootScript.resPath)

if (!rootSourceFile) {
addError({
this.project.errors.add({
description: `Failed to find root source file for ${rootScript.fsPath}`,
error: ErrorName.Ts2GdError,
location: rootScript.fsPath,
Expand All @@ -328,7 +328,7 @@ export class AssetGodotScene extends BaseAsset {
const className = rootSourceFile.exportedTsClassName()

if (!className) {
addError({
this.project.errors.add({
description: `Failed to find classname for ${rootScript.fsPath}`,
error: ErrorName.Ts2GdError,
location: rootScript.fsPath,
Expand Down
Loading

0 comments on commit a43f2d2

Please sign in to comment.