|
| 1 | +# Version & Updates |
| 2 | + |
| 3 | +zigantic includes automatic version checking and error reporting features to help you stay up-to-date and report issues easily. |
| 4 | + |
| 5 | +## Automatic Update Checking |
| 6 | + |
| 7 | +zigantic **automatically** checks for updates in the background when you first use JSON functions (`fromJson`, `toJson`, `toJsonPretty`). No initialization is needed! |
| 8 | + |
| 9 | +When a new version is available, you'll see a log message: |
| 10 | + |
| 11 | +``` |
| 12 | +info: [UPDATE] A newer release of zigantic is available: v0.1.0 (current 0.0.1) |
| 13 | +``` |
| 14 | + |
| 15 | +### Basic Usage (Updates Enabled by Default) |
| 16 | + |
| 17 | +```zig |
| 18 | +const std = @import("std"); |
| 19 | +const z = @import("zigantic"); |
| 20 | +
|
| 21 | +pub fn main() !void { |
| 22 | + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 23 | + defer _ = gpa.deinit(); |
| 24 | +
|
| 25 | + // Just use the library - update check happens automatically! |
| 26 | + const name = try z.String(1, 50).init("Alice"); |
| 27 | + std.debug.print("Hello, {s}!\n", .{name.get()}); |
| 28 | +
|
| 29 | + // Update check triggers on first JSON use |
| 30 | + const User = struct { name: z.String(1, 50) }; |
| 31 | + var result = try z.fromJson(User, "{\"name\": \"Bob\"}", gpa.allocator()); |
| 32 | + defer result.deinit(); |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +## Disabling Automatic Updates |
| 37 | + |
| 38 | +To disable automatic update checking, call `disableUpdateCheck()` **before** using any library functions: |
| 39 | + |
| 40 | +```zig |
| 41 | +const std = @import("std"); |
| 42 | +const z = @import("zigantic"); |
| 43 | +
|
| 44 | +pub fn main() !void { |
| 45 | + // Disable update checking (must be called before any other z.* functions) |
| 46 | + z.disableUpdateCheck(); |
| 47 | +
|
| 48 | + // Now use the library normally - no update checks will occur |
| 49 | + const name = try z.String(1, 50).init("Alice"); |
| 50 | + std.debug.print("Hello, {s}!\n", .{name.get()}); |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +### Custom Configuration |
| 55 | + |
| 56 | +For more control, use `setConfig()`: |
| 57 | + |
| 58 | +```zig |
| 59 | +const z = @import("zigantic"); |
| 60 | +
|
| 61 | +pub fn main() !void { |
| 62 | + // Customize configuration |
| 63 | + z.setConfig(.{ |
| 64 | + .auto_update_check = false, // Disable update checking |
| 65 | + .show_update_notifications = false, // Disable notifications |
| 66 | + }); |
| 67 | +
|
| 68 | + // Use library... |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +### Configuration Options |
| 73 | + |
| 74 | +| Option | Type | Default | Description | |
| 75 | +| --------------------------- | ------ | ------- | ------------------------------------- | |
| 76 | +| `auto_update_check` | `bool` | `true` | Enable/disable automatic update check | |
| 77 | +| `show_update_notifications` | `bool` | `true` | Show update notifications in log | |
| 78 | + |
| 79 | +## Library Version |
| 80 | + |
| 81 | +Get the current version of zigantic: |
| 82 | + |
| 83 | +```zig |
| 84 | +const z = @import("zigantic"); |
| 85 | +
|
| 86 | +const ver = z.getVersion(); // "0.0.1" |
| 87 | +const full = z.getVersionString(); // "v0.0.1" |
| 88 | +``` |
| 89 | + |
| 90 | +## Manual Update Checking |
| 91 | + |
| 92 | +You can also check for updates manually: |
| 93 | + |
| 94 | +### Background Check (Non-blocking) |
| 95 | + |
| 96 | +```zig |
| 97 | +const z = @import("zigantic"); |
| 98 | +
|
| 99 | +pub fn main() !void { |
| 100 | + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 101 | + defer _ = gpa.deinit(); |
| 102 | +
|
| 103 | + // Start background update check |
| 104 | + if (z.checkForUpdates(gpa.allocator())) |thread| { |
| 105 | + // Optional: wait for check to complete on shutdown |
| 106 | + defer thread.join(); |
| 107 | + } |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +### Synchronous Check |
| 112 | + |
| 113 | +```zig |
| 114 | +const z = @import("zigantic"); |
| 115 | +
|
| 116 | +pub fn main() !void { |
| 117 | + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 118 | + defer _ = gpa.deinit(); |
| 119 | +
|
| 120 | + // Check for updates synchronously |
| 121 | + var info = try z.checkForUpdatesSync(gpa.allocator()); |
| 122 | + defer info.deinit(); |
| 123 | +
|
| 124 | + if (info.update_available) { |
| 125 | + std.debug.print("Update available: {s} (current: {s})\n", .{ |
| 126 | + info.latest_version, |
| 127 | + info.current_version, |
| 128 | + }); |
| 129 | + } |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +## Internal Error Reporting |
| 134 | + |
| 135 | +::: warning |
| 136 | +The error reporting functions are for **library bugs only** - unexpected internal errors that might indicate a bug in zigantic itself. |
| 137 | + |
| 138 | +**Do NOT use these for validation errors!** Validation errors (like "value is too short") are expected behavior when users provide invalid data. |
| 139 | +::: |
| 140 | + |
| 141 | +### When to Use Error Reporting |
| 142 | + |
| 143 | +Use `reportInternalError` only when you encounter an unexpected situation in your own code that might be caused by a bug in zigantic: |
| 144 | + |
| 145 | +```zig |
| 146 | +const z = @import("zigantic"); |
| 147 | +
|
| 148 | +fn myLibraryFunction() !void { |
| 149 | + // Some unexpected internal error occurred |
| 150 | + // This might be a bug in zigantic's internals |
| 151 | + z.reportInternalError("Unexpected null value in parsed result"); |
| 152 | + return error.InternalError; |
| 153 | +} |
| 154 | +``` |
| 155 | + |
| 156 | +This prints: |
| 157 | + |
| 158 | +``` |
| 159 | +[ZIGANTIC ERROR] Unexpected null value in parsed result |
| 160 | +
|
| 161 | +If you believe this is a bug in zigantic, please report it at: |
| 162 | + https://github.com/muhammad-fiaz/zigantic/issues |
| 163 | +``` |
| 164 | + |
| 165 | +### Validation Errors (Do NOT Report) |
| 166 | + |
| 167 | +Validation errors are **expected behavior** - don't report them as bugs: |
| 168 | + |
| 169 | +```zig |
| 170 | +const z = @import("zigantic"); |
| 171 | +
|
| 172 | +pub fn main() void { |
| 173 | + // This is normal - validation errors are expected! |
| 174 | + if (z.String(3, 50).init("Jo")) |name| { |
| 175 | + std.debug.print("Valid: {s}\n", .{name.get()}); |
| 176 | + } else |err| { |
| 177 | + // Handle normally - DO NOT call reportError() |
| 178 | + std.debug.print("Validation failed: {s}\n", .{z.errorMessage(err)}); |
| 179 | + } |
| 180 | +} |
| 181 | +``` |
| 182 | + |
| 183 | +### Get Issues URL |
| 184 | + |
| 185 | +```zig |
| 186 | +const z = @import("zigantic"); |
| 187 | +
|
| 188 | +const url = z.ISSUES_URL; // "https://github.com/muhammad-fiaz/zigantic/issues" |
| 189 | +``` |
| 190 | + |
| 191 | +## API Reference |
| 192 | + |
| 193 | +### Functions |
| 194 | + |
| 195 | +| Function | Description | |
| 196 | +| ---------------------------------- | ------------------------------------------------------- | |
| 197 | +| `disableUpdateCheck()` | Disable automatic update checking | |
| 198 | +| `setConfig(config)` | Set custom configuration | |
| 199 | +| `getConfig()` | Get current configuration | |
| 200 | +| `getVersion()` | Get version string (e.g., "0.0.1") | |
| 201 | +| `getVersionString()` | Get full version (e.g., "v0.0.1") | |
| 202 | +| `checkForUpdates(allocator)` | Manually check for updates in background | |
| 203 | +| `checkForUpdatesSync(allocator)` | Manually check for updates synchronously | |
| 204 | +| `reportInternalError(msg)` | Report internal library bug (not for validation errors) | |
| 205 | +| `reportInternalErrorWithCode(err)` | Report internal library bug with error code | |
| 206 | + |
| 207 | +### Constants |
| 208 | + |
| 209 | +| Constant | Description | |
| 210 | +| ------------ | ------------------------------------ | |
| 211 | +| `ISSUES_URL` | GitHub issues URL for reporting bugs | |
0 commit comments