When pg-minify fails, it's hard to locate the issue

Đang mở
#93 8 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
postgresql, typescript
Lĩnh vực
backend, database

Hướng nghiên cứu

Bắt đầu bằng cách đọc dist/commands/watch.js, đặc biệt là lệnh gọi pg-minify xử lý các migration hiện tại, và chạy bản tái hiện được báo cáo của current/12000-insert_iso3166_countries.sql. Theo dõi cách ranh giới của các tệp migration và số dòng của parser được ghép lại; hoàn tất khi lỗi pg-minify xác định được tệp chịu trách nhiệm và dòng gần đúng, đồng thời giữ nguyên lỗi ban đầu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

When pg-minify fails, Graphile Migrate outputs pg-minify's error, but doesn't relate it to the file that actually caused the problem. This is particularly problematic if you have a large (e.g. initial) migration and you're using the current/ folder - you don't know which file the error occurred in.

Steps to reproduce

current/12000-insert_iso3166_countries.sql:

COPY countries (name, alpha_2, code) FROM stdin DELIMITER '|';
Kyrgyzstan|KG|417
Lao People's Democratic Republic|LA|418
Latvia|LV|428
\.
Expected results

Error on line 3 of 12000-insert_iso3166_countries.sql (we don't support COPY syntax).

Actual results
🛑 Error occurred whilst processing migration
    SQLParsingError: Error parsing SQL at {line:24153,col:11}: Unclosed text block.
Additional context

graphile-migrate 1.0.1; linux; current/ folder.

Possible Solution

The following mod to dist/commands/watch.js gives more information:

                let currentBodyMinified;
                try {
                  currentBodyMinified = pgMinify(currentBodyFromDryRun);
                } catch (e) {
                  const matches = e.message.match(/Error parsing SQL at \{line:(\d+),col:(\d+)\}/);
                  if (matches) {
                    const [_, ln, col] = matches;
                    const lines = currentBodyFromDryRun.split("\n");
                    const leadingLines = lines.slice(0, +ln);
                    const lastSplit = [...leadingLines].reverse().find(l => l.match(/^--! split/));
                    let filename = null;
                    let offset = 0;
                    if (lastSplit) {
                      filename = lastSplit.split(':')[1].trim();
                      const index = leadingLines.indexOf(lastSplit);
                      offset = index + 1;
                    }

                    const previousLine = lines[+ln - 2];
                    const line = lines[+ln - 1];
                    const nextLine = lines[+ln];
                    const details = filename ? `current/${filename} line ${+ln - offset}-ish` : `current.sql line ${ln}-ish`
                    console.error(`Error happened around here ${details}:`);
                    console.error();
                    console.error(previousLine || "");
                    console.error(line || "");
                    console.error("-".repeat(+col - 1) + "^");
                    console.error(nextLine || "");
                  }
                  throw e;
                }

produces:

Error happened around here current/12000-insert_iso3166_countries.sql line 3-ish:

Kyrgyzstan|KG|417
Lao People's Democratic Republic|LA|418
----------^
Latvia|LV|428

🛑 Error occurred whilst processing migration
    SQLParsingError: Error parsing SQL at {line:24153,col:11}: Unclosed text block.

Ngôn ngữ chính
TypeScript
Star
836
Fork
71
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của graphile/migrate

Tất cả issue của graphile/migrate

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.