Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Recovery #1501

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 0 additions & 27 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,6 @@ module.exports = {
'**/fixtures',
'!**/.eslintrc.cjs',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
project: [],
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.js', '.cjs', '.mjs', '.mts', '.ts', '.d.ts'],
},
'import/resolver': {
typescript: {},
},
node: {
allowModules: ['@glimmer/debug', '@glimmer/local-debug-flags'],
tryExtensions: ['.js', '.ts', '.d.ts', '.json'],
},
},
plugins: [
'@typescript-eslint',
'prettier',
'qunit',
'simple-import-sort',
'unused-imports',
'prettier',
'n',
],

rules: {},
overrides: [
{
Expand Down
13 changes: 13 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- [ ] Implement `#try` that takes handler
- [ ] internal `{{#if isClear}}{{!-- actual code --}}{{/if}}`
- [ ] if an error is encountered, unwind as-if isClear was false
during the render pass
- [ ] when you encounter the enter of the try, insert a marker in
every VM stack.
- [ ] every stack in the VM needs "unwind to nearest marker"
- [ ] when a render error is encountered, unwind all the stacks
- [ ] call the handler with the error
- [ ] no catch
- [ ] the handler has a way to clear the error
- [ ] deal with user destructors that should run even during render errors
- [ ] maintain the invariant that constructors and destructors are paired
5 changes: 3 additions & 2 deletions benchmark/benchmarks/krausest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
},
"dependencies": {
"@glimmer-workspace/benchmark-env": "workspace:^",
"@glimmer/compiler": "workspace:^",
"@glimmer/interfaces": "workspace:^",
"@simple-dom/document": "^1.4.0",
"@simple-dom/serializer": "^1.4.0",
"@simple-dom/void-map": "^1.4.0"
"@simple-dom/void-map": "^1.4.0",
"@glimmer/compiler": "workspace:^",
"@glimmer/util": "workspace:^"
},
"devDependencies": {
"@types/node": "^20.9.4",
Expand Down
7 changes: 6 additions & 1 deletion benchmark/benchmarks/krausest/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { fileURLToPath } from 'node:url';
const self = import.meta.url;

const currentPath = path.dirname(fileURLToPath(self));
const packagesPath = path.resolve(currentPath, '..', '..', './../packages');
/**
* Only run this vite config via pnpm benchmark:setup at the
* monorepo root
*/
const packagesPath = path.resolve(currentPath, '..', '..', './../');

const packagePath = (name: string) => {
return path.join(packagesPath, name, 'dist/prod/index.js');
Expand All @@ -21,6 +25,7 @@ export default defineConfig({
'@glimmer-workspace/benchmark-env': '@glimmer-workspace/benchmark-env/index.ts',
'@glimmer/debug': packagePath('@glimmer/debug'),
'@glimmer/runtime': packagePath('@glimmer/runtime'),
'@glimmer/util': packagePath('@glimmer/util'),
'@/components': path.join(currentPath, 'lib', 'components'),
'@/utils': path.join(currentPath, 'lib', 'utils'),
},
Expand Down
92 changes: 4 additions & 88 deletions bin/link-all.mts
Original file line number Diff line number Diff line change
@@ -1,98 +1,14 @@
import { readFile, writeFile, unlink } from 'node:fs/promises';
import { join } from 'node:path';
import chalk from 'chalk';
import { execa } from 'execa';
import { mkdirp } from 'mkdirp';
import { rimraf } from 'rimraf';
import { x as untar } from 'tar';
import { packages } from './packages.mjs';
import { writeFileSync } from 'node:fs';
import chalk from 'chalk';

import { previewPublish } from './preview-publish.mjs';

const dist = new URL('../dist', import.meta.url).pathname;
const pkgs = packages('@glimmer');

await mkdirp(dist);
await rimraf(dist + '/*.tgz', { glob: true });

const pack = pkgs.map(async (pkg) => {
try {
await execa('pnpm', ['pack', '--pack-destination', dist], {
cwd: pkg.path,
});

console.log(chalk.green(`Successfully packed ${pkg.name}`));
} catch (error: unknown) {
let message = `Failed to pack ${pkg.name}`;

if (error instanceof Error) {
message += `\n\n${error.stack}`;
}

throw new Error(message);
}
});

await Promise.all(pack);

const unpack = pkgs.map(async (pkg) => {
try {
const pkgDest = join(dist, pkg.name);

await mkdirp(pkgDest);
await rimraf(pkgDest + '/**/*');

const tarball = join(dist, pkg.name.replace('@', '').replace('/', '-') + `-${pkg.version}.tgz`);

await untar({
file: tarball,
strip: 1,
cwd: pkgDest,
});

await unlink(tarball);

// https://github.com/pnpm/pnpm/issues/881
const packageJsonPath = join(pkgDest, 'package.json');
const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' }));
delete packageJson.devDependencies;
await writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), {
encoding: 'utf8',
});

console.log(chalk.green(`Successfully unpacked ${pkg.name}`));
} catch (error: unknown) {
let message = `Failed to unpack ${pkg.name}`;

if (error instanceof Error) {
message += `\n\n${error.stack}`;
}

throw new Error(message);
}
});

await Promise.all(unpack);

const packageJson = `{
"name": "glimmer-vm",
"private": true,
"overrides": {
${pkgs.map((pkg) => ` "${pkg.name}": "workspace:*"`).join(',\n')}
}
}
`;

const workspaceYaml = 'packages:\n' + pkgs.map((pkg) => ` - '${pkg.name}'\n`).join('');

await writeFile(join(dist, 'package.json'), packageJson, { encoding: 'utf8' });
await writeFile(join(dist, 'pnpm-workspace.yaml'), workspaceYaml, { encoding: 'utf8' });

await execa('pnpm', ['install'], {
cwd: dist,
stdio: 'inherit',
});

console.log(chalk.green(`Successfully installed packages`));
await previewPublish();

// Seems like there are race conditions in pnpm if we try to do these concurrently
for (const pkg of pkgs) {
Expand Down
2 changes: 0 additions & 2 deletions bin/opcodes.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { dirname, resolve } from 'node:path';
import chalk from 'chalk';
import { execSync, spawnSync } from 'node:child_process';
import { Emitter } from './opcodes/utils.mjs';

const emitter = Emitter.argv('opcodes.json', import.meta);
Expand Down
4 changes: 2 additions & 2 deletions bin/opcodes/utils.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, relative, resolve } from 'node:path';
import chalk from 'chalk';
import { spawnSync } from 'node:child_process';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, relative, resolve } from 'node:path';

NullVoxPopuli marked this conversation as resolved.
Show resolved Hide resolved
const MISSING_INDEX = -1;
const REMOVE = 1;
Expand Down
2 changes: 1 addition & 1 deletion bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@types/node": "^20.9.4",
"@types/puppeteer-chromium-resolver": "workspace:^",
"@types/tar": "^6.1.10",
"chalk": "^5.2.0",
"chalk": "^5.3.0",
"execa": "^7.1.1",
"glob": "^10.2.3",
"js-yaml": "^4.1.0",
Expand Down
106 changes: 106 additions & 0 deletions bin/preview-publish.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { readFile, writeFile, unlink } from 'node:fs/promises';
import { join } from 'node:path';
import chalk from 'chalk';
import { execa } from 'execa';
import { mkdirp } from 'mkdirp';
import { rimraf } from 'rimraf';
import { x as untar } from 'tar';
import { packages } from './packages.mjs';
import { writeFileSync } from 'node:fs';

export async function previewPublish() {
const dist = new URL('../dist', import.meta.url).pathname;
const pkgs = packages('@glimmer');

await mkdirp(dist);
await rimraf(dist + '/*.tgz', { glob: true });

const pack = pkgs.map(async (pkg) => {
try {
await execa('pnpm', ['pack', '--pack-destination', dist], {
cwd: pkg.path,
});

console.log(chalk.green(`Successfully packed ${pkg.name}`));
} catch (error: unknown) {
let message = `Failed to pack ${pkg.name}`;

if (error instanceof Error) {
message += `\n\n${error.stack}`;
}

throw new Error(message);
}
});

await Promise.all(pack);

const unpack = pkgs.map(async (pkg) => {
try {
const pkgDest = join(dist, pkg.name);

await mkdirp(pkgDest);
await rimraf(pkgDest + '/**/*');

const tarball = join(
dist,
pkg.name.replace('@', '').replace('/', '-') + `-${pkg.version}.tgz`
);

await untar({
file: tarball,
strip: 1,
cwd: pkgDest,
});

await unlink(tarball);

// https://github.com/pnpm/pnpm/issues/881
const packageJsonPath = join(pkgDest, 'package.json');
const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' }));
delete packageJson.devDependencies;
await writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), {
encoding: 'utf8',
});

console.log(chalk.green(`Successfully unpacked ${pkg.name}`));
} catch (error: unknown) {
let message = `Failed to unpack ${pkg.name}`;

if (error instanceof Error) {
message += `\n\n${error.stack}`;
}

throw new Error(message);
}
});

await Promise.all(unpack);

const packageJson = `{
"name": "glimmer-vm",
"private": true,
"overrides": {
${pkgs.map((pkg) => ` "${pkg.name}": "workspace:*"`).join(',\n')}
}
}
`;

const workspaceYaml = 'packages:\n' + pkgs.map((pkg) => ` - '${pkg.name}'\n`).join('');

await writeFile(join(dist, 'package.json'), packageJson, { encoding: 'utf8' });
await writeFile(join(dist, 'pnpm-workspace.yaml'), workspaceYaml, { encoding: 'utf8' });

await execa('pnpm', ['install'], {
cwd: dist,
stdio: 'inherit',
});

console.log(chalk.green(`Successfully installed packages`));
}

if (import.meta.url === 'file://' + process.argv[1]) {
console.log('Previewing Publish...');

await previewPublish();
}
Loading
Loading