toiljs 0.0.135 → 0.0.137

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/build/compiler/compiler-build.d.ts +9 -0
  3. package/build/compiler/compiler-build.js +177 -0
  4. package/build/compiler/compiler-cache.d.ts +28 -0
  5. package/build/compiler/compiler-cache.js +114 -0
  6. package/build/compiler/compiler-lock.d.ts +1 -0
  7. package/build/compiler/compiler-lock.js +99 -0
  8. package/build/compiler/config.d.ts +8 -0
  9. package/build/compiler/config.js +14 -1
  10. package/build/compiler/emails.js +2 -3
  11. package/build/compiler/index.d.ts +3 -2
  12. package/build/compiler/index.js +84 -41
  13. package/build/compiler/prerender.d.ts +1 -0
  14. package/build/compiler/prerender.js +55 -0
  15. package/build/compiler/ssg.js +5 -2
  16. package/build/compiler/template-build.js +10 -10
  17. package/build/compiler/toil-docs.generated.js +6 -6
  18. package/build/compiler/toilscript-worker.d.ts +1 -0
  19. package/build/compiler/toilscript-worker.js +78 -0
  20. package/build/devserver/daemon/index.d.ts +1 -0
  21. package/build/devserver/daemon/index.js +5 -1
  22. package/build/devserver/daemon/runtime.d.ts +1 -0
  23. package/build/devserver/daemon/runtime.js +3 -1
  24. package/build/devserver/production.d.ts +1 -0
  25. package/build/devserver/production.js +2 -1
  26. package/build/devserver/runtime/host.d.ts +1 -0
  27. package/build/devserver/runtime/host.js +2 -0
  28. package/build/devserver/runtime/module.d.ts +2 -1
  29. package/build/devserver/runtime/module.js +6 -4
  30. package/build/devserver/server.d.ts +1 -0
  31. package/build/devserver/server.js +3 -2
  32. package/build/devserver/stream/index.d.ts +1 -1
  33. package/build/devserver/stream/index.js +3 -2
  34. package/build/devserver/stream/manager.d.ts +2 -1
  35. package/build/devserver/stream/manager.js +4 -2
  36. package/build/devserver/stream/router.d.ts +1 -1
  37. package/build/devserver/stream/router.js +2 -2
  38. package/build/logger/index.d.ts +10 -3
  39. package/build/logger/index.js +24 -5
  40. package/package.json +1 -1
  41. package/server/auth/AuthController.ts +17 -0
  42. package/server/auth/GoogleIdentity.ts +4 -0
  43. package/server/globals/toil-log.ts +48 -0
  44. package/server/globals.d.ts +8 -0
  45. package/tsconfig.logger.json +1 -0
@@ -1,5 +1,4 @@
1
1
  import { readDeriveCatalog, deriveIdentity } from 'toiljs/io';
2
- import { spawn } from 'node:child_process';
3
2
  import fs from 'node:fs';
4
3
  import { createRequire } from 'node:module';
5
4
  import net from 'node:net';
@@ -15,6 +14,8 @@ import { prerenderStaticParams } from './ssg.js';
15
14
  import { extractDevSsrTemplates, extractServerSlots, extractTemplates, } from './template-build.js';
16
15
  import { createViteConfig } from './vite.js';
17
16
  import { logSecurityDeployment } from './security-deployment.js';
17
+ import { runCompilerPasses } from './compiler-build.js';
18
+ import { withCompilerLock } from './compiler-lock.js';
18
19
  export const SURFACE_DECORATOR = /^[ \t]*@(data|rest|service|remote|stream|daemon|scheduled)\b/m;
19
20
  function toilconfigEntries(root) {
20
21
  try {
@@ -135,7 +136,12 @@ function serverAuthEnabled(root, configAuth) {
135
136
  return false;
136
137
  return serverImportsAuth(root, serverEntryFiles(root));
137
138
  }
138
- export async function buildServer(root, auth = false) {
139
+ export async function buildServer(root, auth = false, authRoutes = {}, logging = false) {
140
+ if (!fs.existsSync(path.join(root, 'toilconfig.json')))
141
+ return;
142
+ await withCompilerLock(root, () => buildServerLocked(path.resolve(root), auth, authRoutes, logging));
143
+ }
144
+ async function buildServerLocked(root, auth, authRoutes, logging) {
139
145
  if (!fs.existsSync(path.join(root, 'toilconfig.json')))
140
146
  return;
141
147
  for (const dir of serverDirs(root)) {
@@ -150,6 +156,11 @@ export async function buildServer(root, auth = false) {
150
156
  const files = serverEntryFiles(root);
151
157
  const authOn = auth || serverImportsAuth(root, files);
152
158
  if (authOn) {
159
+ const authLib = path.join(root, AUTH_EMAILS_LIB_SUBDIR);
160
+ fs.mkdirSync(authLib, { recursive: true });
161
+ fs.writeFileSync(path.join(authLib, '_auth_routes.ts'), `// Generated by toiljs. Rebuild to change auth route policy.\n` +
162
+ `@inline export function __toilAuthGoogleEnabled(): bool { return ${authRoutes.google !== false}; }\n` +
163
+ `@inline export function __toilAuthTwoFactorSetupEnabled(): bool { return ${authRoutes.twoFactorSetup !== false}; }\n`);
153
164
  const appHasUser = serverDeclaresUser(root, files);
154
165
  const authFiles = authEntryFiles(root, appHasUser);
155
166
  const authSet = new Set(authFiles);
@@ -178,43 +189,58 @@ export async function buildServer(root, auth = false) {
178
189
  }
179
190
  if (split.hasDaemon || split.hasStream) {
180
191
  const artifacts = serverArtifacts(root);
192
+ const passes = [];
181
193
  if (split.hasDaemon)
182
- await runToilscriptPass(root, binJs, split.cold, {
194
+ passes.push(toilscriptPass(root, split.cold, {
183
195
  mode: 'cold',
184
196
  outFile: artifacts.cold,
185
197
  withRpc: false,
186
198
  authUser: authOn,
187
- });
199
+ logging,
200
+ }));
188
201
  if (split.hasStream && split.stream.length > 0)
189
- await runToilscriptPass(root, binJs, split.stream, {
202
+ passes.push(toilscriptPass(root, split.stream, {
190
203
  mode: 'hot',
191
204
  outFile: artifacts.stream,
192
205
  withRpc: false,
193
206
  authUser: authOn,
194
- });
207
+ logging,
208
+ }));
195
209
  if (split.request.length > 0)
196
- await runToilscriptPass(root, binJs, split.request, {
210
+ passes.push(toilscriptPass(root, split.request, {
197
211
  mode: 'hot',
198
212
  outFile: serverWasmFile(root),
199
213
  withRpc: true,
200
214
  rpcSurfaceFiles: split.hasStream ? split.stream : undefined,
201
215
  authUser: authOn,
202
- });
203
- if (split.request.length > 0)
204
- validateDeriveContinuationArtifacts(fs.readFileSync(serverWasmFile(root)), split.hasDaemon ? fs.readFileSync(artifacts.cold) : null);
205
- if (split.hasDaemon)
206
- validateDeriveContinuationArtifacts(null, fs.readFileSync(artifacts.cold));
207
- if (split.hasStream && split.stream.length > 0)
208
- emitStreamClientSurface(root, artifacts.stream, split.stream);
216
+ logging,
217
+ }));
218
+ await runCompilerPasses(root, binJs, passes, () => {
219
+ migrateRpcFile(root);
220
+ if (split.hasStream && split.stream.length > 0)
221
+ emitStreamClientSurface(root, artifacts.stream, split.stream);
222
+ }, {
223
+ validate: (readOutput) => {
224
+ if (split.hasDaemon)
225
+ validateDeriveContinuationArtifacts(null, readOutput(artifacts.cold));
226
+ if (split.request.length > 0)
227
+ validateDeriveContinuationArtifacts(readOutput(serverWasmFile(root)), split.hasDaemon ? readOutput(artifacts.cold) : null);
228
+ },
229
+ });
209
230
  return;
210
231
  }
211
- await runToilscriptPass(root, binJs, files, {
232
+ const pass = toilscriptPass(root, files, {
212
233
  mode: 'hot',
213
234
  outFile: null,
214
235
  withRpc: true,
215
236
  authUser: authOn,
237
+ logging,
238
+ });
239
+ await runCompilerPasses(root, binJs, [pass], () => {
240
+ migrateRpcFile(root);
241
+ }, {
242
+ validate: (readOutput) => validateDeriveContinuationArtifacts(readOutput(serverWasmFile(root)), null),
216
243
  });
217
- validateDeriveContinuationArtifacts(fs.readFileSync(serverWasmFile(root)), null);
218
244
  }
219
245
  export function validateDeriveContinuationArtifacts(hot, cold) {
220
246
  const moduleOf = (bytes) => new WebAssembly.Module(Uint8Array.from(bytes));
@@ -383,8 +409,10 @@ export function assertNoStreamInRequestTier(root, split) {
383
409
  '\nRemove the import, or move the code into a *.stream.ts module.');
384
410
  }
385
411
  }
386
- async function runToilscriptPass(root, binJs, files, opts) {
387
- const args = [binJs, ...files, '--target', 'release'];
412
+ function toilscriptPass(root, files, opts) {
413
+ const args = [...files, '--target', 'release'];
414
+ const logLib = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../server/globals/toil-log.ts');
415
+ args.push('--lib', logLib, '--use', 'Log=ToilLog', '--use', `__TOIL_LOGGING=${opts.logging ? '1' : '0'}`);
388
416
  const editorTier = opts.mode === 'cold' ? 'cold' : opts.withRpc ? 'request' : 'stream';
389
417
  const editorDir = serverDirs(root)[0] ?? path.join(root, 'server');
390
418
  args.push('--editorTypes', path.join(editorDir, `toilscript.${editorTier}.generated.d.ts`));
@@ -396,6 +424,16 @@ async function runToilscriptPass(root, binJs, files, opts) {
396
424
  args.push('--outFile', opts.outFile);
397
425
  if (opts.withRpc)
398
426
  args.push('--rpcModule', 'shared/server.ts');
427
+ else {
428
+ args.push('--rpcModule', '');
429
+ const config = JSON.parse(fs.readFileSync(path.join(root, 'toilconfig.json'), 'utf8'));
430
+ const target = config.targets?.release;
431
+ const text = target?.textFile ?? config.options?.textFile;
432
+ if (text && opts.outFile)
433
+ args.push('--textFile', opts.outFile.replace(/\.[^.]+$/, '') + path.extname(text));
434
+ if ((target?.sourceMap ?? config.options?.sourceMap) && opts.outFile)
435
+ args.push('--sourceMap', path.basename(opts.outFile) + '.map');
436
+ }
399
437
  if (opts.rpcSurfaceFiles)
400
438
  for (const surfaceFile of opts.rpcSurfaceFiles)
401
439
  args.push('--rpcSurfaceFiles', surfaceFile);
@@ -405,22 +443,16 @@ async function runToilscriptPass(root, binJs, files, opts) {
405
443
  args.push('--lib', AUTH_EMAILS_LIB_SUBDIR);
406
444
  args.push('--noConfigEntries');
407
445
  args.push('--disableWarning', '235');
408
- await new Promise((resolve, reject) => {
409
- const child = spawn(process.execPath, args, { cwd: root, stdio: 'inherit' });
410
- child.on('error', reject);
411
- child.on('close', (code) => code === 0
412
- ? resolve()
413
- : reject(new Error(`toilscript ${opts.mode ?? 'release'} build failed (exit ${String(code)})`)));
414
- });
415
- if (opts.withRpc) {
416
- const generated = path.join(root, 'shared/server.ts');
417
- if (fs.existsSync(generated)) {
418
- const source = fs.readFileSync(generated, 'utf8');
419
- const updated = migrateGeneratedRpcClient(source);
420
- if (source !== updated)
421
- fs.writeFileSync(generated, updated);
422
- }
423
- }
446
+ return { name: editorTier, args };
447
+ }
448
+ function migrateRpcFile(root) {
449
+ const generated = path.join(root, 'shared/server.ts');
450
+ if (!fs.existsSync(generated))
451
+ return;
452
+ const source = fs.readFileSync(generated, 'utf8');
453
+ const updated = migrateGeneratedRpcClient(source);
454
+ if (source !== updated)
455
+ fs.writeFileSync(generated, updated);
424
456
  }
425
457
  export function migrateGeneratedRpcClient(source) {
426
458
  return source.replace(/(async function __toilRpcCall\(__id: number, __body: )Uint8Array(?=\))/, '$1Uint8Array<ArrayBuffer>');
@@ -441,9 +473,11 @@ function watchServer(cfg, watcher) {
441
473
  building = true;
442
474
  process.stdout.write(pc.dim(' server changed, rebuilding…') + '\n');
443
475
  const authOn = serverAuthEnabled(root, cfg.auth);
444
- renderEmails(cfg, authOn)
445
- .then(() => renderAuthEmails(cfg, authOn))
446
- .then(() => buildServer(root, cfg.auth))
476
+ withCompilerLock(root, async () => {
477
+ await renderEmails(cfg, authOn);
478
+ await renderAuthEmails(cfg, authOn);
479
+ await buildServerLocked(root, cfg.auth, cfg.authRoutes, cfg.logging ?? true);
480
+ })
447
481
  .then(() => process.stdout.write(pc.green(' ✓ ') + pc.dim('server rebuilt') + '\n'))
448
482
  .catch((e) => process.stdout.write(pc.red(` ✗ server rebuild failed: ${String(e)}`) + '\n'))
449
483
  .finally(() => {
@@ -632,6 +666,9 @@ function isExposedHost(host) {
632
666
  return host !== '127.0.0.1' && host !== 'localhost' && host !== '::1';
633
667
  }
634
668
  export async function dev(opts = {}) {
669
+ return withCompilerLock(path.resolve(opts.root ?? process.cwd()), () => devLocked(opts));
670
+ }
671
+ async function devLocked(opts) {
635
672
  const cfg = await loadConfig(opts);
636
673
  const hasServer = fs.existsSync(path.join(cfg.root, 'toilconfig.json'));
637
674
  if (hasServer)
@@ -642,7 +679,7 @@ export async function dev(opts = {}) {
642
679
  generate(cfg);
643
680
  if (hasServer)
644
681
  await extractServerSlots(cfg);
645
- await buildServer(cfg.root, cfg.auth);
682
+ await buildServerLocked(cfg.root, cfg.auth, cfg.authRoutes, cfg.logging ?? true);
646
683
  if (hasServer)
647
684
  process.stdout.write(pc.green(' ✓ ') + pc.dim('server built') + '\n');
648
685
  if (!hasServer) {
@@ -690,6 +727,7 @@ export async function dev(opts = {}) {
690
727
  streamWasmFile: serverArtifacts(cfg.root).stream,
691
728
  nodeMode: cfg.nodeMode,
692
729
  daemon: cfg.daemon,
730
+ logging: cfg.logging,
693
731
  vite: { host: '127.0.0.1', port: vitePort },
694
732
  email: cfg.email ?? undefined,
695
733
  ssrTemplates,
@@ -718,6 +756,9 @@ export async function dev(opts = {}) {
718
756
  return server;
719
757
  }
720
758
  export async function build(opts = {}) {
759
+ await withCompilerLock(path.resolve(opts.root ?? process.cwd()), () => buildLocked(opts));
760
+ }
761
+ async function buildLocked(opts) {
721
762
  const cfg = await loadConfig(opts);
722
763
  const hasServer = fs.existsSync(path.join(cfg.root, 'toilconfig.json'));
723
764
  if (hasServer && !opts.serverOnly)
@@ -727,7 +768,7 @@ export async function build(opts = {}) {
727
768
  await renderAuthEmails(cfg, authOnBuild);
728
769
  generate(cfg);
729
770
  const priorServerSlots = hasServer ? await extractServerSlots(cfg) : new Map();
730
- await buildServer(cfg.root, cfg.auth);
771
+ await buildServerLocked(cfg.root, cfg.auth, cfg.authRoutes, cfg.logging ?? false);
731
772
  if (opts.serverOnly)
732
773
  return;
733
774
  if (hasServer)
@@ -747,7 +788,7 @@ export async function build(opts = {}) {
747
788
  const ssr = await extractTemplates(cfg, 'edge', priorServerSlots);
748
789
  if (ssr.serverSlotsChanged) {
749
790
  process.stdout.write(pc.dim(' SSR template changed; recompiling the server with the new hash…') + '\n');
750
- await buildServer(cfg.root, cfg.auth);
791
+ await buildServerLocked(cfg.root, cfg.auth, cfg.authRoutes, cfg.logging ?? false);
751
792
  }
752
793
  logSecurityDeployment(cfg);
753
794
  }
@@ -767,6 +808,7 @@ export async function start(opts = {}) {
767
808
  coldWasmFile: artifacts.cold,
768
809
  nodeMode: cfg.nodeMode,
769
810
  daemon: cfg.daemon,
811
+ logging: cfg.logging,
770
812
  threads: opts.threads ?? cfg.threads,
771
813
  port: cfg.port,
772
814
  host: cfg.host,
@@ -972,5 +1014,6 @@ function emitStreamClientSurface(root, streamWasmPath, streamFiles) {
972
1014
  attach +
973
1015
  (typeBlock.length > 0 ? '\n' + typeBlock : '');
974
1016
  fs.mkdirSync(path.dirname(rpcModule), { recursive: true });
975
- fs.writeFileSync(rpcModule, out);
1017
+ if (!fs.existsSync(rpcModule) || fs.readFileSync(rpcModule, 'utf8') !== out)
1018
+ fs.writeFileSync(rpcModule, out);
976
1019
  }
@@ -3,4 +3,5 @@ import { type ResolvedToilConfig } from './config.js';
3
3
  export declare function extractStaticExports(filePath: string, names: readonly string[]): Record<string, Record<string, unknown>>;
4
4
  export declare function extractStaticMetadata(filePath: string): Record<string, unknown> | null;
5
5
  export declare function exportsTrue(filePath: string, name: string): boolean;
6
+ export declare function mayExport(filePath: string, name: string): boolean;
6
7
  export declare function prerenderPlugin(cfg: ResolvedToilConfig): Plugin;
@@ -4,6 +4,16 @@ import { parseSync } from 'oxc-parser';
4
4
  import { patternToBracketFile, scanRoutes, staticSectionPattern } from './routes.js';
5
5
  import { injectSeoHtml, routeSeo } from './seo.js';
6
6
  const UNRESOLVED = Symbol('unresolved');
7
+ function hasCommonJsReference(node) {
8
+ if (Array.isArray(node))
9
+ return node.some(hasCommonJsReference);
10
+ if (node === null || typeof node !== 'object')
11
+ return false;
12
+ const entry = node;
13
+ if (entry.type === 'Identifier' && (entry.name === 'module' || entry.name === 'exports'))
14
+ return true;
15
+ return Object.values(entry).some(hasCommonJsReference);
16
+ }
7
17
  function evalNode(node) {
8
18
  switch (node.type) {
9
19
  case 'Literal':
@@ -112,6 +122,51 @@ export function extractStaticMetadata(filePath) {
112
122
  export function exportsTrue(filePath, name) {
113
123
  return staticExports(filePath, [name])[name] === true;
114
124
  }
125
+ export function mayExport(filePath, name) {
126
+ let source;
127
+ try {
128
+ source = fs.readFileSync(filePath, 'utf8');
129
+ }
130
+ catch {
131
+ return true;
132
+ }
133
+ const parsed = parseSync(filePath, source);
134
+ if (parsed.errors.length)
135
+ return true;
136
+ for (const statement of parsed.program.body) {
137
+ if (statement.type === 'TSExportAssignment')
138
+ return true;
139
+ if (statement.type === 'ExportAllDeclaration') {
140
+ if (!statement.exported)
141
+ return true;
142
+ const exported = statement.exported;
143
+ if (('name' in exported ? exported.name : exported.value) === name)
144
+ return true;
145
+ }
146
+ if (statement.type !== 'ExportNamedDeclaration')
147
+ continue;
148
+ for (const specifier of statement.specifiers) {
149
+ const exported = specifier.exported;
150
+ if (('name' in exported ? exported.name : exported.value) === name)
151
+ return true;
152
+ }
153
+ const declaration = statement.declaration;
154
+ if (declaration?.type === 'VariableDeclaration') {
155
+ for (const entry of declaration.declarations) {
156
+ if (entry.id.type !== 'Identifier' || entry.id.name === name)
157
+ return true;
158
+ }
159
+ }
160
+ else if (declaration &&
161
+ 'id' in declaration &&
162
+ declaration.id &&
163
+ 'name' in declaration.id &&
164
+ declaration.id.name === name) {
165
+ return true;
166
+ }
167
+ }
168
+ return /\b(?:module|exports)\b/.test(source) && hasCommonJsReference(parsed.program);
169
+ }
115
170
  export function prerenderPlugin(cfg) {
116
171
  return {
117
172
  name: 'toil:prerender-seo',
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { createServer } from 'vite';
4
- import { extractStaticMetadata } from './prerender.js';
4
+ import { extractStaticMetadata, mayExport } from './prerender.js';
5
5
  import { scanRoutes } from './routes.js';
6
6
  import { injectSeoHtml, joinUrl, llmsTxt, routeSeo, sitemapXml } from './seo.js';
7
7
  import { createViteConfig } from './vite.js';
@@ -29,7 +29,10 @@ export async function prerenderStaticParams(cfg) {
29
29
  if (!fs.existsSync(shellPath))
30
30
  return [];
31
31
  const allRoutes = scanRoutes(cfg.routesAbsDir);
32
- const dynamic = allRoutes.filter((r) => r.slot === undefined && !r.intercept && /[:*]/.test(r.pattern));
32
+ const dynamic = allRoutes.filter((r) => r.slot === undefined &&
33
+ !r.intercept &&
34
+ /[:*]/.test(r.pattern) &&
35
+ mayExport(r.file, 'generateStaticParams'));
33
36
  if (dynamic.length === 0)
34
37
  return [];
35
38
  const shell = fs.readFileSync(shellPath, 'utf8');
@@ -9,7 +9,7 @@ import { scanRoutes } from './routes.js';
9
9
  import { generateSlotsModule } from './ssr-codegen.js';
10
10
  import { assignSlotIds, coherenceHash, encodeSlots, extractFromHtml, } from './template.js';
11
11
  import { createViteConfig } from './vite.js';
12
- import { extractStaticMetadata } from './prerender.js';
12
+ import { extractStaticMetadata, mayExport } from './prerender.js';
13
13
  import { escapeAttr, escapeHtml, injectSeoHtml, routeSeo } from './seo.js';
14
14
  const SSR_MARKER = '<template id="__toil_ssr"></template>';
15
15
  const ROOT_DIV = '<div id="root"></div>';
@@ -148,7 +148,7 @@ export function writeServerSlotsModules(root, modules) {
148
148
  return written;
149
149
  }
150
150
  async function renderSsrRoutes(cfg, shell) {
151
- const routes = scanRoutes(cfg.routesAbsDir).filter((r) => r.slot === undefined && !r.intercept);
151
+ const routes = scanRoutes(cfg.routesAbsDir).filter((r) => r.slot === undefined && !r.intercept && mayExport(r.file, 'ssr'));
152
152
  if (routes.length === 0)
153
153
  return [];
154
154
  const warn = (msg) => {
@@ -160,16 +160,16 @@ async function renderSsrRoutes(cfg, shell) {
160
160
  appType: 'custom',
161
161
  logLevel: 'silent',
162
162
  });
163
- const client = (await server.ssrLoadModule('toiljs/client'));
164
- const globalsModule = path.join(cfg.toilDir, 'globals.ts');
165
- if (fs.existsSync(globalsModule)) {
166
- await server.ssrLoadModule(globalsModule);
167
- }
168
- const appRequire = createRequire(path.join(cfg.root, 'package.json'));
169
- const react = appRequire('react');
170
- const reactDomServer = appRequire('react-dom/server');
171
163
  const rendered = [];
172
164
  try {
165
+ const client = (await server.ssrLoadModule('toiljs/client'));
166
+ const globalsModule = path.join(cfg.toilDir, 'globals.ts');
167
+ if (fs.existsSync(globalsModule)) {
168
+ await server.ssrLoadModule(globalsModule);
169
+ }
170
+ const appRequire = createRequire(path.join(cfg.root, 'package.json'));
171
+ const react = appRequire('react');
172
+ const reactDomServer = appRequire('react-dom/server');
173
173
  for (const r of routes) {
174
174
  let mod;
175
175
  try {