@volter/world-runtime 2.0.10 → 2.0.11

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.
@@ -46,7 +46,38 @@ export async function branchWorld(base, name, options = {}) {
46
46
  throw new Error(`volter-world branch: ${base} has a managed database, which keeps no history to branch from at an instant or position; branch from its current state`);
47
47
  }
48
48
  refuseLiveDatabases(from, databases);
49
- const instance = await upWorld(existsSync(from.configPath) ? from.configPath : from.config, { name, root, mode: from.mode, envFile });
49
+ // a branch that fails to boot (a twin whose mounted version breaks the config's pin) leaves no half-made branch behind:
50
+ // its record without a fork would check out later as an empty World
51
+ const existed = (() => { try {
52
+ statusWorld(name, root);
53
+ return true;
54
+ }
55
+ catch {
56
+ return false;
57
+ } })();
58
+ let instance;
59
+ try {
60
+ instance = await upWorld(existsSync(from.configPath) ? from.configPath : from.config, { name, root, mode: from.mode, envFile });
61
+ }
62
+ catch (error) {
63
+ let recorded = false;
64
+ if (!existed) {
65
+ try {
66
+ statusWorld(name, root);
67
+ recorded = true;
68
+ }
69
+ catch { /* the boot recorded nothing */ }
70
+ }
71
+ if (recorded) {
72
+ try {
73
+ await downWorld(name, root, { purge: true });
74
+ }
75
+ catch (cleanup) {
76
+ throw new Error(`${error instanceof Error ? error.message : String(error)} (and the half-made branch ${name} could not be removed: ${cleanup instanceof Error ? cleanup.message : String(cleanup)})`);
77
+ }
78
+ }
79
+ throw error;
80
+ }
50
81
  const forked = {};
51
82
  try {
52
83
  if (from.origin) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/world-runtime",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": "World configs for twins: boot named local runtimes, allocate ports, generate world.env/instance.json, and run apps against fake-key twin worlds.",
5
5
  "keywords": [
6
6
  "twin",
package/src/branch.ts CHANGED
@@ -48,7 +48,22 @@ export async function branchWorld(base: string, name: string, options: BranchOpt
48
48
  throw new Error(`volter-world branch: ${base} has a managed database, which keeps no history to branch from at an instant or position; branch from its current state`);
49
49
  }
50
50
  refuseLiveDatabases(from, databases);
51
- const instance = await upWorld(existsSync(from.configPath) ? from.configPath : from.config, { name, root, mode: from.mode, envFile });
51
+ // a branch that fails to boot (a twin whose mounted version breaks the config's pin) leaves no half-made branch behind:
52
+ // its record without a fork would check out later as an empty World
53
+ const existed = (() => { try { statusWorld(name, root); return true; } catch { return false; } })();
54
+ let instance: WorldInstance;
55
+ try {
56
+ instance = await upWorld(existsSync(from.configPath) ? from.configPath : from.config, { name, root, mode: from.mode, envFile });
57
+ } catch (error) {
58
+ let recorded = false;
59
+ if (!existed) { try { statusWorld(name, root); recorded = true; } catch { /* the boot recorded nothing */ } }
60
+ if (recorded) {
61
+ try { await downWorld(name, root, { purge: true }); } catch (cleanup) {
62
+ throw new Error(`${error instanceof Error ? error.message : String(error)} (and the half-made branch ${name} could not be removed: ${cleanup instanceof Error ? cleanup.message : String(cleanup)})`);
63
+ }
64
+ }
65
+ throw error;
66
+ }
52
67
  const forked: Record<string, string[]> = {};
53
68
  try {
54
69
  if (from.origin) { instance.origin = { ...from.origin }; saveWorldInstance(instance); }