Git Product home page Git Product logo

source-error's Introduction

๐Ÿง™โ€โ™€๏ธ๐Ÿ”ฎ

source-error

a magical type for displaying source file errors


๐Ÿ“ฆ install

Add the following to your Cargo.toml file's [dependencies] heading

[dependencies]
source-error = "0.1"

๐Ÿคธ usage

๐Ÿšง Interfaces are not yet finalized and are subject to change

This crate is intended as a visual reporting diagnostic for tools which operate on text sources.

The source_error::Error type provides a helpful Display and can be used on in any Error context

use source_error::{from_file, Position};
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    println!(
        "{}",
        from_file(
            "whoopsie!",
            "path/to/some/file.json",
            Position::new(3, 4)
        )?
    );
    Ok(())
}

Doug Tangren (softprops) 2019

source-error's People

Contributors

softprops avatar

Stargazers

Andrew Radev avatar Michael Cheng avatar  avatar Jan Riemer avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

isabella232

source-error's Issues

consider sources with multiple errors

it may potentially be useful to introduce a source_error::Errors type which captures multiple errors in one type for the same file

let mut homework_errors = source_error::Errors::new(file, src.lines());
errors.add(
  "made a mistake here", (5, 6)
);
errors.add(
 "made another mistake here", (9, 4)
);
println!("{}", errors);

should Debug impl match Display impl?

Display is for humans but rust's default termination behavior for main methods is to render Debug. Hence you might expect this to pretty print the way Display does but instead you'll get the render of the Error types struct fields.

use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
   Err(source_error::from_file(...))?;
   Ok(())
}

pick an visual cue for column

perhaps underscore the letter at that location, but that wont play well when colors are disabled. ^ is typical but may make the line spacing weird

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.