Esempio n. 1
0
void print_err_msg(ErrorMsg *err, ErrColor color) {
    if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) {
        fprintf(stderr, WHITE "%s:%d:%d: " RED "error:" WHITE " %s" RESET "\n",
                buf_ptr(err->path),
                err->line_start + 1, err->column_start + 1,
                buf_ptr(err->msg));

        fprintf(stderr, "%s\n", buf_ptr(&err->line_buf));
        for (int i = 0; i < err->column_start; i += 1) {
            fprintf(stderr, " ");
        }
        fprintf(stderr, GREEN "^" RESET "\n");

    } else {
        fprintf(stderr, "%s:%d:%d: error: %s\n",
                buf_ptr(err->path),
                err->line_start + 1, err->column_start + 1,
                buf_ptr(err->msg));
    }

    for (int i = 0; i < err->notes.length; i += 1) {
        ErrorMsg *note = err->notes.at(i);
        print_err_msg(note, color);
    }
}
Esempio n. 2
0
static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) {
    const char *path = buf_ptr(err->path);
    size_t line = err->line_start + 1;
    size_t col = err->column_start + 1;
    const char *text = buf_ptr(err->msg);


    if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) {
        if (err_type == ErrTypeError) {
            fprintf(stderr, WHITE "%s:%zu:%zu: " RED "error:" WHITE " %s" RESET "\n", path, line, col, text);
        } else if (err_type == ErrTypeNote) {
            fprintf(stderr, WHITE "%s:%zu:%zu: " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text);
        } else {
            zig_unreachable();
        }

        fprintf(stderr, "%s\n", buf_ptr(&err->line_buf));
        for (size_t i = 0; i < err->column_start; i += 1) {
            fprintf(stderr, " ");
        }
        fprintf(stderr, GREEN "^" RESET "\n");
    } else {
        if (err_type == ErrTypeError) {
            fprintf(stderr, "%s:%zu:%zu: error: %s\n", path, line, col, text);
        } else if (err_type == ErrTypeNote) {
            fprintf(stderr, " %s:%zu:%zu: note: %s\n", path, line, col, text);
        } else {
            zig_unreachable();
        }
    }

    for (size_t i = 0; i < err->notes.length; i += 1) {
        ErrorMsg *note = err->notes.at(i);
        print_err_msg_type(note, color, ErrTypeNote);
    }
}