这是indexloc提供的服务,不要输入任何密码
Skip to content

Import truncation & generic error in formatting file #1544

@jmortiger

Description

@jmortiger

When formatting the file, an error occurred. This is the console command & output:

dart format --summary profile ./lib/util/tag_db_import.dart 
Hit a bug in the formatter when formatting ./lib/util/tag_db_import.dart. 
The formatter produced unexpected output. Input was:
import 'package:archive/archive.dart' as archive
  if (dart.library.io) 'package:archive/archive_io.dart';
import 'package:flutter/services.dart';
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
  _print("Tag Database Decompressed!");
  return TagDB.makeFromCsvString(vf);
}
Future<TagDB> _androidCallback(http.StreamedResponse value) {
  return decompressGzPlainTextStream(value).then(_core);
}
Future<TagDB> _webCallback(ByteData data) {
  return http.ByteStream.fromBytes(
            archive.GZipDecoder().decodeBuffer(archive.InputStream(data)))
        .bytesToString()
        .then(_core);
}
final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {       
  if (Platform.isWeb) {
    var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");    
    _print("Tag Database Loaded!");
    return compute(_webCallback, data);
  } else {
    return
        E621.sendRequest(e621.Api.initDbExportRequest())
        .then((value) => compute(_androidCallback, value));
        // E621ApiEndpoints.dbExportTags
        // .getMoreData()
        // .sendRequest()
        // .then((value) => compute(_androidCallback, value));
  }
});
Which formatted to:
    if (dart.library.io) 'package:archive/archive_io.dart' as archive;
import 'package:flutter/services.dart';
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
  _print("Tag Database Decompressed!");
  return TagDB.makeFromCsvString(vf);
}

Future<TagDB> _androidCallback(http.StreamedResponse value) {
  return decompressGzPlainTextStream(value).then(_core);
}

Future<TagDB> _webCallback(ByteData data) {
  return http.ByteStream.fromBytes(
          archive.GZipDecoder().decodeBuffer(archive.InputStream(data)))
      .bytesToString()
      .then(_core);
}

final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {
  if (Platform.isWeb) {
    var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");
    _print("Tag Database Loaded!");
    return compute(_webCallback, data);
  } else {
    return E621
        .sendRequest(e621.Api.initDbExportRequest())
        .then((value) => compute(_androidCallback, value));
    // E621ApiEndpoints.dbExportTags
    // .getMoreData()
    // .sendRequest()
    // .then((value) => compute(_androidCallback, value));
  }
});

Please report at github.com/dart-lang/dart_style/issues.

This does display a clear problem that would result in a compile-time error; the removal of the first line, part of the conditional import. However, after I switched its placement with the following flutter/services import, the tool now yielded no compile-time error, yet still failed in the console. Here is that command & output:

dart format --output show ./lib/util/tag_db_import.dart
Hit a bug in the formatter when formatting ./lib/util/tag_db_import.dart.
The formatter produced unexpected output. Input was:
import 'package:flutter/services.dart';
import 'package:archive/archive.dart' as archive
  if (dart.library.io) 'package:archive/archive_io.dart';
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
  _print("Tag Database Decompressed!");
  return TagDB.makeFromCsvString(vf);
}
Future<TagDB> _androidCallback(http.StreamedResponse value) {
  return decompressGzPlainTextStream(value).then(_core);
}
Future<TagDB> _webCallback(ByteData data) {
  return http.ByteStream.fromBytes(
            archive.GZipDecoder().decodeBuffer(archive.InputStream(data)))
        .bytesToString()
        .then(_core);
}
final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {
  if (Platform.isWeb) {
    var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");
    _print("Tag Database Loaded!");
    return compute(_webCallback, data);
  } else {
    return
        E621.sendRequest(e621.Api.initDbExportRequest())
        .then((value) => compute(_androidCallback, value));
        // E621ApiEndpoints.dbExportTags
        // .getMoreData()
        // .sendRequest()
        // .then((value) => compute(_androidCallback, value));
  }
});
Which formatted to:
import 'package:flutter/services.dart';
import 'package:archive/archive.dart'
    if (dart.library.io) 'package:archive/archive_io.dart' as archive;
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
  _print("Tag Database Decompressed!");
  return TagDB.makeFromCsvString(vf);
}

Future<TagDB> _androidCallback(http.StreamedResponse value) {
  return decompressGzPlainTextStream(value).then(_core);
}

Future<TagDB> _webCallback(ByteData data) {
  return http.ByteStream.fromBytes(
          archive.GZipDecoder().decodeBuffer(archive.InputStream(data)))
      .bytesToString()
      .then(_core);
}

final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {
  if (Platform.isWeb) {
    var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");
    _print("Tag Database Loaded!");
    return compute(_webCallback, data);
  } else {
    return E621
        .sendRequest(e621.Api.initDbExportRequest())
        .then((value) => compute(_androidCallback, value));
    // E621ApiEndpoints.dbExportTags
    // .getMoreData()
    // .sendRequest()
    // .then((value) => compute(_androidCallback, value));
  }
});

Please report at github.com/dart-lang/dart_style/issues.
Formatted no files in 0.24 seconds.

After this, I tested the prior ordering, and, for some reason, this now also yielded no compilation errors while still failing in the console. Here is that output:

dart format --output show ./lib/util/tag_db_import.dart
Hit a bug in the formatter when formatting ./lib/util/tag_db_import.dart.
The formatter produced unexpected output. Input was:
import 'package:archive/archive.dart' as archive
  if (dart.library.io) 'package:archive/archive_io.dart';
import 'package:flutter/services.dart';
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
  _print("Tag Database Decompressed!");
  return TagDB.makeFromCsvString(vf);
}
Future<TagDB> _androidCallback(http.StreamedResponse value) {
  return decompressGzPlainTextStream(value).then(_core);
}
Future<TagDB> _webCallback(ByteData data) {
  return http.ByteStream.fromBytes(
            archive.GZipDecoder().decodeBuffer(archive.InputStream(data)))
        .bytesToString()
        .then(_core);
}
final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {
  if (Platform.isWeb) {
    var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");
    _print("Tag Database Loaded!");
    return compute(_webCallback, data);
  } else {
    return
        E621.sendRequest(e621.Api.initDbExportRequest())
        .then((value) => compute(_androidCallback, value));
        // E621ApiEndpoints.dbExportTags
        // .getMoreData()
        // .sendRequest()
        // .then((value) => compute(_androidCallback, value));
  }
});
Which formatted to:
import 'package:archive/archive.dart'
    if (dart.library.io) 'package:archive/archive_io.dart' as archive;
import 'package:flutter/services.dart';
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
  _print("Tag Database Decompressed!");
  return TagDB.makeFromCsvString(vf);
}

Future<TagDB> _androidCallback(http.StreamedResponse value) {
  return decompressGzPlainTextStream(value).then(_core);
}

Future<TagDB> _webCallback(ByteData data) {
  return http.ByteStream.fromBytes(
          archive.GZipDecoder().decodeBuffer(archive.InputStream(data)))
      .bytesToString()
      .then(_core);
}

final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {
  if (Platform.isWeb) {
    var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");
    _print("Tag Database Loaded!");
    return compute(_webCallback, data);
  } else {
    return E621
        .sendRequest(e621.Api.initDbExportRequest())
        .then((value) => compute(_androidCallback, value));
    // E621ApiEndpoints.dbExportTags
    // .getMoreData()
    // .sendRequest()
    // .then((value) => compute(_androidCallback, value));
  }
});

Please report at github.com/dart-lang/dart_style/issues.
Formatted no files in 0.25 seconds.

I eventually assumed the explicit error was the constant casing on the identifier, as the command succeeded after changing it, but after attempting to stage the file and copy the old version to reproduce the bug, it now works fine despite that. The initially listed input still fails when pasted into the file, but produces different output, no longer cutting the import. I'm at a loss.

This was the version output:

dart format --version
2.3.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions