Skip to content

Handle unexpected exceptions during Azure metadata detection - #189457

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
Ahmet-Can-Urhan:fix-azure-metadata-argumenterror
Aug 4, 2026
Merged

auto-submit[bot] merged 7 commits into
flutter:masterfrom
Ahmet-Can-Urhan:fix-azure-metadata-argumenterror

Conversation

@Ahmet-Can-Urhan

Copy link
Copy Markdown
Contributor

Description

Azure metadata detection is a best-effort environment check and should never prevent the Flutter CLI from starting.

In some network environments (for example, transparent proxies or enterprise firewalls), requests to the Azure metadata endpoint (http://169.254.169.254/metadata/instance) may result in unexpected exceptions instead of the currently expected network-related exceptions. These exceptions currently propagate and terminate the Flutter CLI.

This change catches unexpected exceptions during Azure metadata detection and treats them as "not running on Azure", which is consistent with the behavior for other metadata lookup failures.

A regression test has been added to verify this behavior.

Issues

#189456

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a generic catch block to the Azure metadata detector to prevent unexpected exceptions from blocking Flutter startup, along with a corresponding unit test. Feedback on the changes includes correcting a typo ('FLutter' to 'Flutter') in a code comment and fixing the indentation and formatting of the new test to comply with the dart format style guide.

Comment thread packages/flutter_tools/lib/src/base/bot_detector.dart Outdated
Comment thread packages/flutter_tools/test/general.shard/base/bot_detector_test.dart Outdated
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 14, 2026
@bkonyi
bkonyi self-requested a review July 23, 2026 22:34

@bkonyi bkonyi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

One minor comment, but this basically LGTM!

} on OSError {
// The HttpClient might be running in a WSL1 environment.
return _isRunningOnAzure = false;
} catch (_) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be on Object { instead.

@Ahmet-Can-Urhan Ahmet-Can-Urhan Jul 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Updated to on Object {. Thanks!

@Ahmet-Can-Urhan
Ahmet-Can-Urhan requested a review from bkonyi July 26, 2026 09:15
} on OSError {
// The HttpClient might be running in a WSL1 environment.
return _isRunningOnAzure = false;
} on Object {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an extra space after Object that the formatter won't be happy about :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad :D
Done!

@Ahmet-Can-Urhan
Ahmet-Can-Urhan requested a review from bkonyi July 28, 2026 05:39
bkonyi
bkonyi previously approved these changes Jul 29, 2026
@bkonyi bkonyi added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Jul 29, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 29, 2026
@auto-submit

auto-submit Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/189457, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a member of flutter-hackers before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@auto-submit

auto-submit Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/189457, because - The status or check suite check-engine-changes has failed. Please fix the issues identified (or deflake) before re-applying this label.

@bkonyi
bkonyi requested a review from chingjun July 29, 2026 17:39
} on OSError {
// The HttpClient might be running in a WSL1 environment.
return _isRunningOnAzure = false;
} on Object {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on Object is very unidiomatic. Since this is supposed to be a catch-all for all exception types, why don't we remove all the other cases, and keeping only on HttpException?

try {
   ...
} on HttpException {
  //....
  return _isRunningOnAzure = true;
} catch (e) {
  // ...
  return _isRunningOnAzure = false;
}

@Ahmet-Can-Urhan Ahmet-Can-Urhan Jul 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach makes much more sense, I will change my pull request accordingly. Thanks for the suggestion.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 29, 2026
@Ahmet-Can-Urhan
Ahmet-Can-Urhan requested a review from chingjun July 29, 2026 19:30
@chingjun chingjun added the CICD Run CI/CD label Jul 29, 2026
@chingjun

Copy link
Copy Markdown
Contributor

Oops, looks like my suggestion actually broke the linter, it is actually recommended to write on Object to catch all. Sorry about that.

But the other part of my suggestion still holds, that we should remove the other exception types now that we have a catch all.

So this should be:

try {
   ...
} on HttpException {
  //....
  return _isRunningOnAzure = true;
} on Object {
  // ...
  return _isRunningOnAzure = false;
}

@Ahmet-Can-Urhan

Ahmet-Can-Urhan commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Oops, looks like my suggestion actually broke the linter, it is actually recommended to write on Object to catch all. Sorry about that.

But the other part of my suggestion still holds, that we should remove the other exception types now that we have a catch all.

So this should be:

try {
   ...
} on HttpException {
  //....
  return _isRunningOnAzure = true;
} on Object {
  // ...
  return _isRunningOnAzure = false;
}

lib/src/base on fix-azure-metadata-argumenterror ❯ flutter analyze bot_detector.dart
Analyzing bot_detector.dart...

info • Catch clause should use 'on' to specify the type of
exception being caught. Try adding an 'on' clause
before the 'catch' • bot_detector.dart:114:7 •
avoid_catches_without_on_clauses

Yeah, I forgot to analyze it before i commit.

Indeed, this new structure still remains though.

Done.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 30, 2026
@bkonyi bkonyi added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Jul 30, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 31, 2026
@auto-submit

auto-submit Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/189457, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@chingjun
chingjun force-pushed the fix-azure-metadata-argumenterror branch from 08ab19e to f26066c Compare July 31, 2026 16:38
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 31, 2026
@chingjun chingjun added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 31, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 31, 2026
@auto-submit

auto-submit Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/189457, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@chingjun

Copy link
Copy Markdown
Contributor

The tests are failing because of an infra issue. I'll submit the PR once the infra issue is resolved.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 3, 2026
@Ahmet-Can-Urhan
Ahmet-Can-Urhan force-pushed the fix-azure-metadata-argumenterror branch from 5d05938 to 3727595 Compare August 3, 2026 22:21
@bkonyi bkonyi added the CICD Run CI/CD label Aug 4, 2026
@chingjun chingjun added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 4, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 4, 2026
Merged via the queue into flutter:master with commit 6e7cc56 Aug 4, 2026
27 of 28 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 4, 2026
@Ahmet-Can-Urhan
Ahmet-Can-Urhan deleted the fix-azure-metadata-argumenterror branch August 4, 2026 19:20
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Aug 10, 2026
…12420)

Manual roll requested by [email protected]

flutter/flutter@b766512...27b0988

2026-08-05 [email protected] reland(tool): remove redundant --enable-experiment=record-use flag (flutter/flutter#190591)
2026-08-05 [email protected] Windows: Propagate enabled accessibility state (flutter/flutter#190507)
2026-08-05 [email protected] Roll Fuchsia Test Scripts from ltbuIH9Z3T_yOuigu... to vcANVO8VIDQHasH1X... (flutter/flutter#190589)
2026-08-05 [email protected] Document frozen embedder API structs (flutter/flutter#186842)
2026-08-05 [email protected] Document super call order for State.didChangeDependencies (flutter/flutter#185945)
2026-08-05 [email protected] Move examples of `flutter/widgets` widgets out from `flutter/material` (flutter/flutter#189532)
2026-08-05 [email protected] [web] Use thread local strike caches in skwasm (flutter/flutter#190048)
2026-08-05 [email protected] doc: fix typo in see also section for PrimaryScrollController.maybeOf (flutter/flutter#190386)
2026-08-05 [email protected] Migrate the shell unit tests from legacy Dart native functions to FFI (flutter/flutter#190473)
2026-08-05 [email protected] render proxy box now defaults baseline calculation to null (flutter/flutter#190269)
2026-08-05 [email protected] Update Widgets Localizations from Translation Console (flutter/flutter#190503)
2026-08-04 [email protected] Revert: fix(tool): remove redundant --enable-experiment=record-use flag (flutter/flutter#190583)
2026-08-04 [email protected] Roll Fuchsia Test Scripts from 1frGe_KltAJKkeyPg... to ltbuIH9Z3T_yOuigu... (flutter/flutter#190561)
2026-08-04 [email protected] iOS,macOS: add tsan and ubsan support for Swift (flutter/flutter#190497)
2026-08-04 [email protected] fix: update on_message_ to nullptr after window destroy so that dart gets destroy message  (flutter/flutter#185807)
2026-08-04 [email protected] [flutter_tools] Gracefully handle locked Windows files during clean (flutter/flutter#190095)
2026-08-04 [email protected] iOS,macOS: make Logger thread-safe, conform to Sendable (flutter/flutter#190488)
2026-08-04 [email protected] iOS: Eliminate use of IOSContextNoop in platform view tests (reland) (flutter/flutter#190509)
2026-08-04 [email protected] fix(tool): remove redundant --enable-experiment=record-use flag (flutter/flutter#190475)
2026-08-04 [email protected] android_hardware_smoke_test: Detect blank image failures or EGL initialization warnings and retry (flutter/flutter#190110)
2026-08-04 [email protected] Bumps text gamma on windows to match skia. (flutter/flutter#190477)
2026-08-04 [email protected] Roll Skia from 48b58ee222f1 to a8583a0a2c11 (2 revisions) (flutter/flutter#190537)
2026-08-04 [email protected] [tool][web] Intercept dart2wasm errors & append JS migration footers (flutter/flutter#190476)
2026-08-04 [email protected] [record_use] Migrate IconTreeShaker to `package:record_use` (flutter/flutter#190225)
2026-08-04 [email protected] Handle unexpected exceptions during Azure metadata detection (flutter/flutter#189457)
2026-08-04 [email protected] Fix merge conflict from flutter/flutter#190369 (flutter/flutter#190544)
2026-08-04 [email protected] Prepare device support symbols (flutter/flutter#190369)
2026-08-04 [email protected] Roll Packages from ac87e65 to 3498b9d (1 revision) (flutter/flutter#190532)
2026-08-04 [email protected] Roll Skia from a08d918ebd6a to 48b58ee222f1 (11 revisions) (flutter/flutter#190527)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants