chore: updated error handling and added null as an option 8ff55eec
Steve · 2025-10-30 22:39 3 file(s) · +67 −17
src/commands/edit.ts +44 −10
52 52
		});
53 53
54 54
		spinner.stop();
55 -
		console.log(`✓ TXT record set successfully`);
55 +
		if (options.value === "") {
56 +
			console.log(`✓ TXT record cleared successfully`);
57 +
		} else {
58 +
			console.log(`✓ TXT record set successfully`);
59 +
		}
56 60
		console.log(`Transaction hash: ${hash}`);
57 61
	} catch (error) {
58 62
		const e = error as { shortMessage?: string; message: string };
59 63
		spinner.stop();
60 64
		console.error("Error setting TXT record:", e.shortMessage || e.message);
65 +
		console.error(
66 +
			"If you are receiving HTTP errors consider setting ETH_RPC_URL as an environemnt variable",
67 +
		);
61 68
	}
62 69
}
63 70
109 116
		const e = error as { shortMessage?: string; message: string };
110 117
		spinner.stop();
111 118
		console.error("Error setting address record:", e.shortMessage || e.message);
119 +
		console.error(
120 +
			"If you are receiving HTTP errors consider setting ETH_RPC_URL as an environemnt variable",
121 +
		);
112 122
	}
113 123
}
114 124
142 152
		const e = error as { shortMessage?: string; message: string };
143 153
		spinner.stop();
144 154
		console.error("Error setting resolver:", e.shortMessage || e.message);
155 +
		console.error(
156 +
			"If you are receiving HTTP errors consider setting ETH_RPC_URL as an environemnt variable",
157 +
		);
145 158
	}
146 159
}
147 160
169 182
		const e = error as { shortMessage?: string; message: string };
170 183
		spinner.stop();
171 184
		console.error("Error setting primary name:", e.shortMessage || e.message);
185 +
		console.error(
186 +
			"If you are receiving HTTP errors consider setting ETH_RPC_URL as an environemnt variable",
187 +
		);
172 188
	}
173 189
}
174 190
190 206
			return;
191 207
		}
192 208
193 -
		// Read ABI file
194 -
		const abiContent = await readFile(options.abiPath, "utf-8");
195 -
		const abi = JSON.parse(abiContent);
209 +
		let encodedAbi: `0x${string}`;
196 210
197 -
		// Encode ABI
198 -
		const encodedAbi = await encodeAbi({
199 -
			encodeAs: options.encodeAs || "json",
200 -
			data: abi,
201 -
		});
211 +
		// Handle null case to clear ABI
212 +
		if (options.abiPath === "null") {
213 +
			// Encode empty ABI to clear the record
214 +
			encodedAbi = await encodeAbi({
215 +
				encodeAs: options.encodeAs || "json",
216 +
				data: null,
217 +
			});
218 +
		} else {
219 +
			// Read ABI file
220 +
			const abiContent = await readFile(options.abiPath, "utf-8");
221 +
			const abi = JSON.parse(abiContent);
222 +
223 +
			// Encode ABI
224 +
			encodedAbi = await encodeAbi({
225 +
				encodeAs: options.encodeAs || "json",
226 +
				data: abi,
227 +
			});
228 +
		}
202 229
203 230
		// Get resolver if not provided
204 231
		let resolverAddress = options.resolverAddress;
223 250
		});
224 251
225 252
		spinner.stop();
226 -
		console.log(`✓ ABI record set successfully`);
253 +
		if (options.abiPath === "null") {
254 +
			console.log(`✓ ABI record cleared successfully`);
255 +
		} else {
256 +
			console.log(`✓ ABI record set successfully`);
257 +
		}
227 258
		console.log(`Transaction hash: ${hash}`);
228 259
	} catch (error) {
229 260
		const e = error as { shortMessage?: string; message: string };
230 261
		spinner.stop();
231 262
		console.error("Error setting ABI record:", e.shortMessage || e.message);
263 +
		console.error(
264 +
			"If you are receiving HTTP errors consider setting ETH_RPC_URL as an environemnt variable",
265 +
		);
232 266
	}
233 267
}
src/commands/resolve.ts +9 −0
41 41
			const e = error as { shortMessage: string };
42 42
			spinner.stop();
43 43
			console.error("Error fetching TXT record:", e.shortMessage);
44 +
			console.error(
45 +
				"If you are receiving HTTP errors consider setting ETH_RPC_URL as an environemnt variable",
46 +
			);
44 47
		}
45 48
		return;
46 49
	}
57 60
			const e = error as { shortMessage: string };
58 61
			spinner.stop();
59 62
			console.error("Error fetching content hash:", e.shortMessage);
63 +
			console.error(
64 +
				"If you are receiving HTTP errors consider setting ETH_RPC_URL as an environemnt variable",
65 +
			);
60 66
		}
61 67
		return;
62 68
	}
73 79
			const e = error as { shortMessage: string };
74 80
			spinner.stop();
75 81
			console.error("Error fetching chain record:", e.shortMessage);
82 +
			console.error(
83 +
				"If you are receiving HTTP errors consider setting ETH_RPC_URL as an environemnt variable",
84 +
			);
76 85
		}
77 86
		spinner.stop();
78 87
		return;
src/index.ts +14 −7
157 157
158 158
const editTxt = command({
159 159
	name: "txt",
160 -
	description: "Set TXT record for an ENS name",
160 +
	description:
161 +
		"Set TXT record for an ENS name (use 'null' to clear the record)",
161 162
	args: {
162 163
		name: positional({
163 164
			type: string,
169 170
		}),
170 171
		value: positional({
171 172
			type: string,
172 -
			description: "Value of the TXT record being set, e.g. myusername",
173 +
			description:
174 +
				"Value of the TXT record being set (use 'null' to clear), e.g. myusername",
173 175
		}),
174 176
		resolverAddress: option({
175 177
			type: optional(string),
180 182
		}),
181 183
	},
182 184
	handler: async (args) => {
183 -
		if (!args.name || !args.record || !args.value) {
185 +
		if (!args.name || !args.record || args.value === undefined) {
184 186
			console.log(
185 187
				"Please provide all required arguments: `atlas edit txt <name> <record> <value>`",
186 188
			);
187 189
			return;
188 190
		}
189 -
		await setTxtCmd(args);
191 +
		await setTxtCmd({
192 +
			...args,
193 +
			value: args.value === "null" ? "" : args.value,
194 +
		});
190 195
	},
191 196
});
192 197
281 286
282 287
const editAbi = command({
283 288
	name: "abi",
284 -
	description: "Set ABI record for an ENS name",
289 +
	description:
290 +
		"Set ABI record for an ENS name (use 'null' to clear the record)",
285 291
	args: {
286 292
		name: positional({
287 293
			type: string,
289 295
		}),
290 296
		abiPath: positional({
291 297
			type: string,
292 -
			description: "Path to ABI JSON file",
298 +
			description: "Path to ABI JSON file (use 'null' to clear)",
293 299
		}),
294 300
		encodeAs: option({
295 301
			type: optional(string),
306 312
		}),
307 313
	},
308 314
	handler: async (args) => {
309 -
		if (!args.name || !args.abiPath) {
315 +
		if (!args.name || args.abiPath === undefined) {
310 316
			console.log(
311 317
				"Please provide all required arguments: `atlas edit abi <name> <abiPath>`",
312 318
			);
314 320
		}
315 321
		await setAbiCmd({
316 322
			...args,
323 +
			abiPath: args.abiPath,
317 324
			encodeAs: (args.encodeAs as "json" | "zlib" | "cbor" | "uri") || "json",
318 325
		});
319 326
	},