Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Tile fallback feature throws error on failure when fallbackUrl not defined #1554

Closed
envomer opened this issue Jun 12, 2023 · 1 comment · Fixed by #1555
Closed

[BUG] Tile fallback feature throws error on failure when fallbackUrl not defined #1554

envomer opened this issue Jun 12, 2023 · 1 comment · Fixed by #1555
Labels
bug This issue reports broken functionality or another error

Comments

@envomer
Copy link
Contributor

envomer commented Jun 12, 2023

What is the bug?

First thanks for the great library!

I upgraded to flutter_map 5.0.0 and now i am getting errors thrown if a tile image does not exist.
This error to be precise: flutter: Invalid argument(s): No host specified in URI

After taking a deeper look, this error is being generated from FlutterMapNetworkImageProvider provider.

When a tile does not exist on the remote server, the httpClient will throw an exception which will be caught and the _loadAsync will be called again with the useFallback argument. IT will try to use the fallback url, but when no fallback url is defined it will use an empty string. That however will throw a No host specified in URI error. Does it even make sense to retry if no fallback url is defined?

// tile_provider.dart:59
  Future<Codec> _loadAsync(
    FlutterMapNetworkImageProvider key,
    StreamController<ImageChunkEvent> chunkEvents,
    ImageDecoderCallback decode, {
    bool useFallback = false,
  }) async {
    final Uint8List bytes;
    try {
      bytes = await httpClient.readBytes(
        Uri.parse(useFallback ? fallbackUrl ?? '' : url),
        headers: headers,
      );
    } catch (_) {
      if (useFallback) rethrow;
      return _loadAsync(key, chunkEvents, decode, useFallback: true);
    }

    return decode(await ImmutableBuffer.fromUint8List(bytes));
  }
  

How can we reproduce it?

  • Load a map with missing tiles

Use the following tile provider:

TileLayer(
      urlTemplate: info.url,
      backgroundColor: Colors.black,
      additionalOptions: const {'noWrap': 'true'},
      reset: resetController.stream,
      panBuffer: 1,
    );

Do you have a potential solution?

Maybe a retry should only be triggered if a fallback is set? What do you think?

Platforms

MacOS

Severity

Minimum: Allows normal functioning

@envomer envomer added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Jun 12, 2023
@envomer envomer changed the title [BUG] Fallback called although with empty url [BUG] Tile fallback called although with empty url (FlutterMapNetworkImageProvider) Jun 12, 2023
@JaffaKetchup
Copy link
Member

Hi @envomer,
I do believe this to be a bug. Thanks for reporting!

@JaffaKetchup JaffaKetchup added non-fatal and removed needs triage This new bug report needs reproducing and prioritizing labels Jun 12, 2023
@JaffaKetchup JaffaKetchup self-assigned this Jun 12, 2023
@JaffaKetchup JaffaKetchup changed the title [BUG] Tile fallback called although with empty url (FlutterMapNetworkImageProvider) [BUG] Tile fallback feature throws error on failure when fallbackUrl not defined Jun 13, 2023
@JaffaKetchup JaffaKetchup removed their assignment Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue reports broken functionality or another error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants