utils

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2025 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package utils provides general-purpose utilities for JSON handling and panic recovery.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRecoveredPanic is returned when a panic is recovered and converted to an error.
	ErrRecoveredPanic = errors.New("recovered panic")

	// ErrCouldNotRepairJSON is returned when malformed JSON cannot be automatically fixed.
	ErrCouldNotRepairJSON = errors.New("malformed JSON could not be repaired")
)

Functions

func JSONFromMarkdown

func JSONFromMarkdown(content string) string

JSONFromMarkdown extracts JSON content from a given Markdown string. If a JSON block is found, it returns the JSON content as a string. If no JSON block is found, it returns the original content.

func NoPanic

func NoPanic(fn func() error) (err error)

NoPanic executes the provided function and recovers from any panic by converting it to error if that occurs.

func RepairTextJSON

func RepairTextJSON(content string) (string, error)

RepairTextJSON attempts to repair common issues with plain-text JSON generated by LLMs. If the input is already valid JSON, it is returned as-is.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL