MCPcopy Create free account
hub / github.com/ElementsProject/lightning / context_snippet

Function context_snippet

common/splice_script.c:294–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

292}
293
294static char *context_snippet(const tal_t *ctx,
295 const char *script,
296 struct splice_script_error *error)
297{
298 const char *start = script + error->script_index;
299 const char *last = start;
300 const char *end = script + strlen(script);
301 char *str;
302
303 for (size_t i = 0; i < CODE_SNIPPET_PADDING && start-1 >= script && start[-1] >= ' '; i++)
304 start--;
305
306 for (size_t i = 0; i < CODE_SNIPPET_PADDING && last < end && last[0] >= ' '; i++)
307 last++;
308
309 str = tal_strndup(ctx, start, last - start);
310
311 tal_append_fmt(&str, "\n");
312
313 for (const char *ptr = start; ptr < script + error->script_index; ptr++)
314 tal_append_fmt(&str, " ");
315
316 tal_append_fmt(&str, "^\n");
317
318 if (error->message && strlen(error->message))
319 tal_append_fmt(&str, "%s\n", error->message);
320
321 if (error->phase)
322 tal_append_fmt(&str, "Compiler phase: %s\n", error->phase);
323
324 return str;
325}
326
327char *fmt_splice_script_compiler_error(const tal_t *ctx,
328 const char *script,

Callers 1

Calls 1

tal_append_fmtFunction · 0.85

Tested by

no test coverage detected