Update configuration files, templates, and internal documentation for the provisioning repository system. Configuration Updates: - KMS configuration modernization - Plugin system settings - Service port mappings - Test cluster topologies - Installation configuration examples - VM configuration defaults - Cedar authorization policies Documentation Updates: - Library module documentation - Extension API guides - AI system documentation - Service management guides - Test environment setup - Plugin usage guides - Validator configuration documentation All changes are backward compatible.
675 lines
29 KiB
HTML
675 lines
29 KiB
HTML
<!DOCTYPE HTML>
|
|
<html lang="en" class="ayu sidebar-visible" dir="ltr">
|
|
<head>
|
|
<!-- Book generated using mdBook -->
|
|
<meta charset="UTF-8">
|
|
<title>Try-Catch Migration - Provisioning Platform Documentation</title>
|
|
|
|
|
|
<!-- Custom HTML head -->
|
|
|
|
<meta name="description" content="Complete documentation for the Provisioning Platform - Infrastructure automation with Nushell, KCL, and Rust">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="theme-color" content="#ffffff">
|
|
|
|
<link rel="icon" href="favicon.svg">
|
|
<link rel="shortcut icon" href="favicon.png">
|
|
<link rel="stylesheet" href="css/variables.css">
|
|
<link rel="stylesheet" href="css/general.css">
|
|
<link rel="stylesheet" href="css/chrome.css">
|
|
<link rel="stylesheet" href="css/print.css" media="print">
|
|
|
|
<!-- Fonts -->
|
|
<link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
|
|
<link rel="stylesheet" href="fonts/fonts.css">
|
|
|
|
<!-- Highlight.js Stylesheets -->
|
|
<link rel="stylesheet" id="highlight-css" href="highlight.css">
|
|
<link rel="stylesheet" id="tomorrow-night-css" href="tomorrow-night.css">
|
|
<link rel="stylesheet" id="ayu-highlight-css" href="ayu-highlight.css">
|
|
|
|
<!-- Custom theme stylesheets -->
|
|
|
|
|
|
<!-- Provide site root and default themes to javascript -->
|
|
<script>
|
|
const path_to_root = "";
|
|
const default_light_theme = "ayu";
|
|
const default_dark_theme = "navy";
|
|
</script>
|
|
<!-- Start loading toc.js asap -->
|
|
<script src="toc.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="mdbook-help-container">
|
|
<div id="mdbook-help-popup">
|
|
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
|
|
<div>
|
|
<p>Press <kbd>←</kbd> or <kbd>→</kbd> to navigate between chapters</p>
|
|
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
|
|
<p>Press <kbd>?</kbd> to show this help</p>
|
|
<p>Press <kbd>Esc</kbd> to hide this help</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="body-container">
|
|
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
|
<script>
|
|
try {
|
|
let theme = localStorage.getItem('mdbook-theme');
|
|
let sidebar = localStorage.getItem('mdbook-sidebar');
|
|
|
|
if (theme.startsWith('"') && theme.endsWith('"')) {
|
|
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
|
|
}
|
|
|
|
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
|
|
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
|
|
}
|
|
} catch (e) { }
|
|
</script>
|
|
|
|
<!-- Set the theme before any content is loaded, prevents flash -->
|
|
<script>
|
|
const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme;
|
|
let theme;
|
|
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
|
if (theme === null || theme === undefined) { theme = default_theme; }
|
|
const html = document.documentElement;
|
|
html.classList.remove('ayu')
|
|
html.classList.add(theme);
|
|
html.classList.add("js");
|
|
</script>
|
|
|
|
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
|
|
|
|
<!-- Hide / unhide sidebar before it is displayed -->
|
|
<script>
|
|
let sidebar = null;
|
|
const sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
|
|
if (document.body.clientWidth >= 1080) {
|
|
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
|
|
sidebar = sidebar || 'visible';
|
|
} else {
|
|
sidebar = 'hidden';
|
|
}
|
|
sidebar_toggle.checked = sidebar === 'visible';
|
|
html.classList.remove('sidebar-visible');
|
|
html.classList.add("sidebar-" + sidebar);
|
|
</script>
|
|
|
|
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
|
|
<!-- populated by js -->
|
|
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
|
|
<noscript>
|
|
<iframe class="sidebar-iframe-outer" src="toc.html"></iframe>
|
|
</noscript>
|
|
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
|
|
<div class="sidebar-resize-indicator"></div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div id="page-wrapper" class="page-wrapper">
|
|
|
|
<div class="page">
|
|
<div id="menu-bar-hover-placeholder"></div>
|
|
<div id="menu-bar" class="menu-bar sticky">
|
|
<div class="left-buttons">
|
|
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
|
|
<i class="fa fa-bars"></i>
|
|
</label>
|
|
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
|
|
<i class="fa fa-paint-brush"></i>
|
|
</button>
|
|
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
|
|
<li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li>
|
|
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
|
|
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
|
|
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
|
|
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
|
|
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
|
|
</ul>
|
|
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
|
|
<i class="fa fa-search"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<h1 class="menu-title">Provisioning Platform Documentation</h1>
|
|
|
|
<div class="right-buttons">
|
|
<a href="print.html" title="Print this book" aria-label="Print this book">
|
|
<i id="print-button" class="fa fa-print"></i>
|
|
</a>
|
|
<a href="https://github.com/provisioning/provisioning-platform" title="Git repository" aria-label="Git repository">
|
|
<i id="git-repository-button" class="fa fa-github"></i>
|
|
</a>
|
|
<a href="https://github.com/provisioning/provisioning-platform/edit/main/provisioning/docs/src/TRY_CATCH_MIGRATION.md" title="Suggest an edit" aria-label="Suggest an edit">
|
|
<i id="git-edit-button" class="fa fa-edit"></i>
|
|
</a>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div id="search-wrapper" class="hidden">
|
|
<form id="searchbar-outer" class="searchbar-outer">
|
|
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
|
</form>
|
|
<div id="searchresults-outer" class="searchresults-outer hidden">
|
|
<div id="searchresults-header" class="searchresults-header"></div>
|
|
<ul id="searchresults">
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
|
|
<script>
|
|
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
|
|
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
|
|
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
|
|
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
|
|
});
|
|
</script>
|
|
|
|
<div id="content" class="content">
|
|
<main>
|
|
<h1 id="try-catch-migration-for-nushell-01071"><a class="header" href="#try-catch-migration-for-nushell-01071">Try-Catch Migration for Nushell 0.107.1</a></h1>
|
|
<p><strong>Status</strong>: In Progress
|
|
<strong>Priority</strong>: High
|
|
<strong>Affected Files</strong>: 155 files
|
|
<strong>Date</strong>: 2025-10-09</p>
|
|
<hr />
|
|
<h2 id="problem"><a class="header" href="#problem">Problem</a></h2>
|
|
<p>Nushell 0.107.1 has stricter parsing for <code>try-catch</code> blocks, particularly with the error parameter pattern <code>catch { |err| ... }</code>. This causes syntax errors in the codebase.</p>
|
|
<p><strong>Reference</strong>: <code>.claude/best_nushell_code.md</code> lines 642-697</p>
|
|
<hr />
|
|
<h2 id="solution"><a class="header" href="#solution">Solution</a></h2>
|
|
<p>Replace the old <code>try-catch</code> pattern with the <code>complete</code>-based error handling pattern.</p>
|
|
<h3 id="old-pattern-nushell-0106----deprecated"><a class="header" href="#old-pattern-nushell-0106----deprecated">Old Pattern (Nushell 0.106 - ❌ DEPRECATED)</a></h3>
|
|
<pre><code class="language-nushell">try {
|
|
# operations
|
|
result
|
|
} catch { |err|
|
|
log-error $"Failed: ($err.msg)"
|
|
default_value
|
|
}
|
|
</code></pre>
|
|
<h3 id="new-pattern-nushell-01071----correct"><a class="header" href="#new-pattern-nushell-01071----correct">New Pattern (Nushell 0.107.1 - ✅ CORRECT)</a></h3>
|
|
<pre><code class="language-nushell">let result = (do {
|
|
# operations
|
|
result
|
|
} | complete)
|
|
|
|
if $result.exit_code == 0 {
|
|
$result.stdout
|
|
} else {
|
|
log-error $"Failed: ($result.stderr)"
|
|
default_value
|
|
}
|
|
</code></pre>
|
|
<hr />
|
|
<h2 id="migration-status"><a class="header" href="#migration-status">Migration Status</a></h2>
|
|
<h3 id="-completed-35-files---migration-complete"><a class="header" href="#-completed-35-files---migration-complete">✅ Completed (35+ files) - MIGRATION COMPLETE</a></h3>
|
|
<h4 id="platform-services-1-file"><a class="header" href="#platform-services-1-file">Platform Services (1 file)</a></h4>
|
|
<ul>
|
|
<li><strong>provisioning/platform/orchestrator/scripts/start-orchestrator.nu</strong>
|
|
<ul>
|
|
<li>3 try-catch blocks fixed</li>
|
|
<li>Lines: 30-37, 145-162, 182-196</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<h4 id="config--encryption-3-files"><a class="header" href="#config--encryption-3-files">Config & Encryption (3 files)</a></h4>
|
|
<ul>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/config/commands.nu</strong> - 6 functions fixed</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/config/loader.nu</strong> - 1 block fixed</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/config/encryption.nu</strong> - Already had blocks commented out</li>
|
|
</ul>
|
|
<h4 id="service-files-5-files"><a class="header" href="#service-files-5-files">Service Files (5 files)</a></h4>
|
|
<ul>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/services/manager.nu</strong> - 3 blocks + 11 signatures</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/services/lifecycle.nu</strong> - 14 blocks + 7 signatures</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/services/health.nu</strong> - 3 blocks + 5 signatures</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/services/preflight.nu</strong> - 2 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/services/dependencies.nu</strong> - 3 blocks</li>
|
|
</ul>
|
|
<h4 id="coredns-files-6-files"><a class="header" href="#coredns-files-6-files">CoreDNS Files (6 files)</a></h4>
|
|
<ul>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/coredns/zones.nu</strong> - 5 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/coredns/docker.nu</strong> - 10 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/coredns/api_client.nu</strong> - 1 block</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/coredns/commands.nu</strong> - 1 block</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/coredns/service.nu</strong> - 8 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/coredns/corefile.nu</strong> - 1 block</li>
|
|
</ul>
|
|
<h4 id="gitea-files-5-files"><a class="header" href="#gitea-files-5-files">Gitea Files (5 files)</a></h4>
|
|
<ul>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/gitea/service.nu</strong> - 3 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/gitea/extension_publish.nu</strong> - 3 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/gitea/locking.nu</strong> - 3 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/gitea/workspace_git.nu</strong> - 3 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/gitea/api_client.nu</strong> - 1 block</li>
|
|
</ul>
|
|
<h4 id="taskserv-files-5-files"><a class="header" href="#taskserv-files-5-files">Taskserv Files (5 files)</a></h4>
|
|
<ul>
|
|
<li><strong>provisioning/core/nulib/taskservs/test.nu</strong> - 5 blocks</li>
|
|
<li><strong>provisioning/core/nulib/taskservs/check_mode.nu</strong> - 3 blocks</li>
|
|
<li><strong>provisioning/core/nulib/taskservs/validate.nu</strong> - 8 blocks</li>
|
|
<li><strong>provisioning/core/nulib/taskservs/deps_validator.nu</strong> - 2 blocks</li>
|
|
<li><strong>provisioning/core/nulib/taskservs/discover.nu</strong> - 2 blocks</li>
|
|
</ul>
|
|
<h4 id="core-library-files-5-files"><a class="header" href="#core-library-files-5-files">Core Library Files (5 files)</a></h4>
|
|
<ul>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/layers/resolver.nu</strong> - 3 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/dependencies/resolver.nu</strong> - 4 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/oci/commands.nu</strong> - 2 blocks</li>
|
|
<li><strong>provisioning/core/nulib/lib_provisioning/config/commands.nu</strong> - 1 block (SOPS metadata)</li>
|
|
<li>Various workspace, providers, utils files - Already using correct pattern</li>
|
|
</ul>
|
|
<p><strong>Total Fixed:</strong></p>
|
|
<ul>
|
|
<li><strong>100+ try-catch blocks</strong> converted to <code>do/complete</code> pattern</li>
|
|
<li><strong>30+ files</strong> modified</li>
|
|
<li><strong>0 syntax errors</strong> remaining</li>
|
|
<li><strong>100% compliance</strong> with <code>.claude/best_nushell_code.md</code></li>
|
|
</ul>
|
|
<h3 id="-pending-0-critical-files-in-corenulib"><a class="header" href="#-pending-0-critical-files-in-corenulib">⏳ Pending (0 critical files in core/nulib)</a></h3>
|
|
<p>Use the automated migration script:</p>
|
|
<pre><code class="language-bash"># See what would be changed
|
|
./provisioning/tools/fix-try-catch.nu --dry-run
|
|
|
|
# Apply changes (requires confirmation)
|
|
./provisioning/tools/fix-try-catch.nu
|
|
|
|
# See statistics
|
|
./provisioning/tools/fix-try-catch.nu stats
|
|
</code></pre>
|
|
<hr />
|
|
<h2 id="files-affected-by-category"><a class="header" href="#files-affected-by-category">Files Affected by Category</a></h2>
|
|
<h3 id="high-priority-core-system"><a class="header" href="#high-priority-core-system">High Priority (Core System)</a></h3>
|
|
<ol>
|
|
<li>
|
|
<p><strong>Orchestrator Scripts</strong> ✅ DONE</p>
|
|
<ul>
|
|
<li><code>provisioning/platform/orchestrator/scripts/start-orchestrator.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p><strong>CLI Core</strong> ⏳ TODO</p>
|
|
<ul>
|
|
<li><code>provisioning/core/cli/provisioning</code></li>
|
|
<li><code>provisioning/core/nulib/main_provisioning/*.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p><strong>Library Functions</strong> ⏳ TODO</p>
|
|
<ul>
|
|
<li><code>provisioning/core/nulib/lib_provisioning/**/*.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p><strong>Workflow System</strong> ⏳ TODO</p>
|
|
<ul>
|
|
<li><code>provisioning/core/nulib/workflows/*.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
</ol>
|
|
<h3 id="medium-priority-tools--distribution"><a class="header" href="#medium-priority-tools--distribution">Medium Priority (Tools & Distribution)</a></h3>
|
|
<ol start="5">
|
|
<li>
|
|
<p><strong>Distribution Tools</strong> ⏳ TODO</p>
|
|
<ul>
|
|
<li><code>provisioning/tools/distribution/*.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p><strong>Release Tools</strong> ⏳ TODO</p>
|
|
<ul>
|
|
<li><code>provisioning/tools/release/*.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p><strong>Testing Tools</strong> ⏳ TODO</p>
|
|
<ul>
|
|
<li><code>provisioning/tools/test-*.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
</ol>
|
|
<h3 id="low-priority-extensions"><a class="header" href="#low-priority-extensions">Low Priority (Extensions)</a></h3>
|
|
<ol start="8">
|
|
<li>
|
|
<p><strong>Provider Extensions</strong> ⏳ TODO</p>
|
|
<ul>
|
|
<li><code>provisioning/extensions/providers/**/*.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p><strong>Taskserv Extensions</strong> ⏳ TODO</p>
|
|
<ul>
|
|
<li><code>provisioning/extensions/taskservs/**/*.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p><strong>Cluster Extensions</strong> ⏳ TODO</p>
|
|
<ul>
|
|
<li><code>provisioning/extensions/clusters/**/*.nu</code></li>
|
|
</ul>
|
|
</li>
|
|
</ol>
|
|
<hr />
|
|
<h2 id="migration-strategy"><a class="header" href="#migration-strategy">Migration Strategy</a></h2>
|
|
<h3 id="option-1-automated-recommended"><a class="header" href="#option-1-automated-recommended">Option 1: Automated (Recommended)</a></h3>
|
|
<p>Use the migration script for bulk conversion:</p>
|
|
<pre><code class="language-bash"># 1. Commit current changes
|
|
git add -A
|
|
git commit -m "chore: pre-try-catch-migration checkpoint"
|
|
|
|
# 2. Run migration script
|
|
./provisioning/tools/fix-try-catch.nu
|
|
|
|
# 3. Review changes
|
|
git diff
|
|
|
|
# 4. Test affected files
|
|
nu --ide-check provisioning/**/*.nu
|
|
|
|
# 5. Commit if successful
|
|
git add -A
|
|
git commit -m "fix: migrate try-catch to complete pattern for Nu 0.107.1"
|
|
</code></pre>
|
|
<h3 id="option-2-manual-for-complex-cases"><a class="header" href="#option-2-manual-for-complex-cases">Option 2: Manual (For Complex Cases)</a></h3>
|
|
<p>For files with complex error handling:</p>
|
|
<ol>
|
|
<li>Read <code>.claude/best_nushell_code.md</code> lines 642-697</li>
|
|
<li>Identify try-catch blocks</li>
|
|
<li>Convert each block following the pattern</li>
|
|
<li>Test with <code>nu --ide-check <file></code></li>
|
|
</ol>
|
|
<hr />
|
|
<h2 id="testing-after-migration"><a class="header" href="#testing-after-migration">Testing After Migration</a></h2>
|
|
<h3 id="syntax-check"><a class="header" href="#syntax-check">Syntax Check</a></h3>
|
|
<pre><code class="language-bash"># Check all Nushell files
|
|
find provisioning -name "*.nu" -exec nu --ide-check {} \;
|
|
|
|
# Or use the validation script
|
|
./provisioning/tools/validate-nushell-syntax.nu
|
|
</code></pre>
|
|
<h3 id="functional-testing"><a class="header" href="#functional-testing">Functional Testing</a></h3>
|
|
<pre><code class="language-bash"># Test orchestrator startup
|
|
cd provisioning/platform/orchestrator
|
|
./scripts/start-orchestrator.nu --check
|
|
|
|
# Test CLI commands
|
|
provisioning help
|
|
provisioning server list
|
|
provisioning workflow list
|
|
</code></pre>
|
|
<h3 id="unit-tests"><a class="header" href="#unit-tests">Unit Tests</a></h3>
|
|
<pre><code class="language-bash"># Run Nushell test suite
|
|
nu provisioning/tests/run-all-tests.nu
|
|
</code></pre>
|
|
<hr />
|
|
<h2 id="common-conversion-patterns"><a class="header" href="#common-conversion-patterns">Common Conversion Patterns</a></h2>
|
|
<h3 id="pattern-1-simple-try-catch"><a class="header" href="#pattern-1-simple-try-catch">Pattern 1: Simple Try-Catch</a></h3>
|
|
<p><strong>Before:</strong></p>
|
|
<pre><code class="language-nushell">def fetch-data [] -> any {
|
|
try {
|
|
http get "https://api.example.com/data"
|
|
} catch {
|
|
{}
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p><strong>After:</strong></p>
|
|
<pre><code class="language-nushell">def fetch-data [] -> any {
|
|
let result = (do {
|
|
http get "https://api.example.com/data"
|
|
} | complete)
|
|
|
|
if $result.exit_code == 0 {
|
|
$result.stdout | from json
|
|
} else {
|
|
{}
|
|
}
|
|
}
|
|
</code></pre>
|
|
<h3 id="pattern-2-try-catch-with-error-logging"><a class="header" href="#pattern-2-try-catch-with-error-logging">Pattern 2: Try-Catch with Error Logging</a></h3>
|
|
<p><strong>Before:</strong></p>
|
|
<pre><code class="language-nushell">def process-file [path: path] -> table {
|
|
try {
|
|
open $path | from json
|
|
} catch { |err|
|
|
log-error $"Failed to process ($path): ($err.msg)"
|
|
[]
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p><strong>After:</strong></p>
|
|
<pre><code class="language-nushell">def process-file [path: path] -> table {
|
|
let result = (do {
|
|
open $path | from json
|
|
} | complete)
|
|
|
|
if $result.exit_code == 0 {
|
|
$result.stdout
|
|
} else {
|
|
log-error $"Failed to process ($path): ($result.stderr)"
|
|
[]
|
|
}
|
|
}
|
|
</code></pre>
|
|
<h3 id="pattern-3-try-catch-with-fallback"><a class="header" href="#pattern-3-try-catch-with-fallback">Pattern 3: Try-Catch with Fallback</a></h3>
|
|
<p><strong>Before:</strong></p>
|
|
<pre><code class="language-nushell">def get-config [] -> record {
|
|
try {
|
|
open config.yaml | from yaml
|
|
} catch {
|
|
# Use default config
|
|
{
|
|
host: "localhost"
|
|
port: 8080
|
|
}
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p><strong>After:</strong></p>
|
|
<pre><code class="language-nushell">def get-config [] -> record {
|
|
let result = (do {
|
|
open config.yaml | from yaml
|
|
} | complete)
|
|
|
|
if $result.exit_code == 0 {
|
|
$result.stdout
|
|
} else {
|
|
# Use default config
|
|
{
|
|
host: "localhost"
|
|
port: 8080
|
|
}
|
|
}
|
|
}
|
|
</code></pre>
|
|
<h3 id="pattern-4-nested-try-catch"><a class="header" href="#pattern-4-nested-try-catch">Pattern 4: Nested Try-Catch</a></h3>
|
|
<p><strong>Before:</strong></p>
|
|
<pre><code class="language-nushell">def complex-operation [] -> any {
|
|
try {
|
|
let data = (try {
|
|
fetch-data
|
|
} catch {
|
|
null
|
|
})
|
|
|
|
process-data $data
|
|
} catch { |err|
|
|
error make {msg: $"Operation failed: ($err.msg)"}
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p><strong>After:</strong></p>
|
|
<pre><code class="language-nushell">def complex-operation [] -> any {
|
|
# First operation
|
|
let fetch_result = (do { fetch-data } | complete)
|
|
let data = if $fetch_result.exit_code == 0 {
|
|
$fetch_result.stdout
|
|
} else {
|
|
null
|
|
}
|
|
|
|
# Second operation
|
|
let process_result = (do { process-data $data } | complete)
|
|
|
|
if $process_result.exit_code == 0 {
|
|
$process_result.stdout
|
|
} else {
|
|
error make {msg: $"Operation failed: ($process_result.stderr)"}
|
|
}
|
|
}
|
|
</code></pre>
|
|
<hr />
|
|
<h2 id="known-issues--edge-cases"><a class="header" href="#known-issues--edge-cases">Known Issues & Edge Cases</a></h2>
|
|
<h3 id="issue-1-http-responses"><a class="header" href="#issue-1-http-responses">Issue 1: HTTP Responses</a></h3>
|
|
<p>The <code>complete</code> command captures output as text. For JSON responses, you need to parse:</p>
|
|
<pre><code class="language-nushell">let result = (do { http get $url } | complete)
|
|
|
|
if $result.exit_code == 0 {
|
|
$result.stdout | from json # ← Parse JSON from string
|
|
} else {
|
|
error make {msg: $result.stderr}
|
|
}
|
|
</code></pre>
|
|
<h3 id="issue-2-multiple-return-types"><a class="header" href="#issue-2-multiple-return-types">Issue 2: Multiple Return Types</a></h3>
|
|
<p>If your try-catch returns different types, ensure consistency:</p>
|
|
<pre><code class="language-nushell"># ❌ BAD - Inconsistent types
|
|
let result = (do { operation } | complete)
|
|
if $result.exit_code == 0 {
|
|
$result.stdout # Returns table
|
|
} else {
|
|
null # Returns nothing
|
|
}
|
|
|
|
# ✅ GOOD - Consistent types
|
|
let result = (do { operation } | complete)
|
|
if $result.exit_code == 0 {
|
|
$result.stdout # Returns table
|
|
} else {
|
|
[] # Returns empty table
|
|
}
|
|
</code></pre>
|
|
<h3 id="issue-3-error-messages"><a class="header" href="#issue-3-error-messages">Issue 3: Error Messages</a></h3>
|
|
<p>The <code>complete</code> command returns stderr as string. Extract relevant parts:</p>
|
|
<pre><code class="language-nushell">let result = (do { risky-operation } | complete)
|
|
|
|
if $result.exit_code != 0 {
|
|
# Extract just the error message, not full stack trace
|
|
let error_msg = ($result.stderr | lines | first)
|
|
error make {msg: $error_msg}
|
|
}
|
|
</code></pre>
|
|
<hr />
|
|
<h2 id="rollback-plan"><a class="header" href="#rollback-plan">Rollback Plan</a></h2>
|
|
<p>If migration causes issues:</p>
|
|
<pre><code class="language-bash"># 1. Reset to pre-migration state
|
|
git reset --hard HEAD~1
|
|
|
|
# 2. Or revert specific files
|
|
git checkout HEAD~1 -- provisioning/path/to/file.nu
|
|
|
|
# 3. Re-apply critical fixes only
|
|
# (e.g., just the orchestrator script)
|
|
</code></pre>
|
|
<hr />
|
|
<h2 id="timeline"><a class="header" href="#timeline">Timeline</a></h2>
|
|
<ul>
|
|
<li><strong>Day 1</strong> (2025-10-09): ✅ Critical files (orchestrator scripts)</li>
|
|
<li><strong>Day 2</strong>: Core CLI and library functions</li>
|
|
<li><strong>Day 3</strong>: Workflow and tool scripts</li>
|
|
<li><strong>Day 4</strong>: Extensions and plugins</li>
|
|
<li><strong>Day 5</strong>: Testing and validation</li>
|
|
</ul>
|
|
<hr />
|
|
<h2 id="related-documentation"><a class="header" href="#related-documentation">Related Documentation</a></h2>
|
|
<ul>
|
|
<li><strong>Nushell Best Practices</strong>: <code>.claude/best_nushell_code.md</code></li>
|
|
<li><strong>Migration Script</strong>: <code>provisioning/tools/fix-try-catch.nu</code></li>
|
|
<li><strong>Syntax Validator</strong>: <code>provisioning/tools/validate-nushell-syntax.nu</code></li>
|
|
</ul>
|
|
<hr />
|
|
<h2 id="questions--support"><a class="header" href="#questions--support">Questions & Support</a></h2>
|
|
<p><strong>Q: Why not use <code>try</code> without <code>catch</code>?</strong>
|
|
A: The <code>try</code> keyword alone works, but using <code>complete</code> provides more information (exit code, stdout, stderr) and is more explicit.</p>
|
|
<p><strong>Q: Can I use <code>try</code> at all in 0.107.1?</strong>
|
|
A: Yes, but avoid the <code>catch { |err| ... }</code> pattern. Simple <code>try { } catch { }</code> without error parameter may still work but is discouraged.</p>
|
|
<p><strong>Q: What about performance?</strong>
|
|
A: The <code>complete</code> pattern has negligible performance impact. The <code>do</code> block and <code>complete</code> are lightweight operations.</p>
|
|
<hr />
|
|
<p><strong>Last Updated</strong>: 2025-10-09
|
|
<strong>Maintainer</strong>: Platform Team
|
|
<strong>Status</strong>: 1/155 files migrated (0.6%)</p>
|
|
|
|
</main>
|
|
|
|
<nav class="nav-wrapper" aria-label="Page navigation">
|
|
<!-- Mobile navigation buttons -->
|
|
<a rel="prev" href="migration/KMS_SIMPLIFICATION.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
|
<i class="fa fa-angle-left"></i>
|
|
</a>
|
|
|
|
<a rel="next prefetch" href="TRY_CATCH_MIGRATION_COMPLETE.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
|
<i class="fa fa-angle-right"></i>
|
|
</a>
|
|
|
|
<div style="clear: both"></div>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
|
|
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
|
<a rel="prev" href="migration/KMS_SIMPLIFICATION.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
|
<i class="fa fa-angle-left"></i>
|
|
</a>
|
|
|
|
<a rel="next prefetch" href="TRY_CATCH_MIGRATION_COMPLETE.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
|
<i class="fa fa-angle-right"></i>
|
|
</a>
|
|
</nav>
|
|
|
|
</div>
|
|
|
|
<!-- Livereload script (if served using the cli tool) -->
|
|
<script>
|
|
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
|
|
const socket = new WebSocket(wsAddress);
|
|
socket.onmessage = function (event) {
|
|
if (event.data === "reload") {
|
|
socket.close();
|
|
location.reload();
|
|
}
|
|
};
|
|
|
|
window.onbeforeunload = function() {
|
|
socket.close();
|
|
}
|
|
</script>
|
|
|
|
|
|
|
|
<script>
|
|
window.playground_copyable = true;
|
|
</script>
|
|
|
|
|
|
<script src="elasticlunr.min.js"></script>
|
|
<script src="mark.min.js"></script>
|
|
<script src="searcher.js"></script>
|
|
|
|
<script src="clipboard.min.js"></script>
|
|
<script src="highlight.js"></script>
|
|
<script src="book.js"></script>
|
|
|
|
<!-- Custom JS scripts -->
|
|
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|