[Notes] [Git][BuildStream/buildstream][master] 2 commits: source.py: don't let StopIteration propagate to silence() contextmanager



Title: GitLab

richardmaw-codethink pushed to branch master at BuildStream / buildstream

Commits:

1 changed file:

Changes:

  • buildstream/source.py
    ... ... @@ -973,32 +973,34 @@ class Source(Plugin):
    973 973
                 # the items of source_fetchers, if it happens to be a generator.
    
    974 974
                 #
    
    975 975
                 source_fetchers = iter(source_fetchers)
    
    976
    -            try:
    
    977 976
     
    
    978
    -                while True:
    
    977
    +            while True:
    
    979 978
     
    
    980
    -                    with context.silence():
    
    979
    +                with context.silence():
    
    980
    +                    try:
    
    981 981
                             fetcher = next(source_fetchers)
    
    982
    -
    
    983
    -                    alias = fetcher._get_alias()
    
    984
    -                    for uri in project.get_alias_uris(alias, first_pass=self.__first_pass):
    
    985
    -                        try:
    
    986
    -                            fetcher.fetch(uri)
    
    987
    -                        # FIXME: Need to consider temporary vs. permanent failures,
    
    988
    -                        #        and how this works with retries.
    
    989
    -                        except BstError as e:
    
    990
    -                            last_error = e
    
    991
    -                            continue
    
    992
    -
    
    993
    -                        # No error, we're done with this fetcher
    
    982
    +                    except StopIteration:
    
    983
    +                        # as per PEP479, we are not allowed to let StopIteration
    
    984
    +                        # thrown from a context manager.
    
    985
    +                        # Catching it here and breaking instead.
    
    994 986
                             break
    
    995 987
     
    
    996
    -                    else:
    
    997
    -                        # No break occurred, raise the last detected error
    
    998
    -                        raise last_error
    
    988
    +                alias = fetcher._get_alias()
    
    989
    +                for uri in project.get_alias_uris(alias, first_pass=self.__first_pass):
    
    990
    +                    try:
    
    991
    +                        fetcher.fetch(uri)
    
    992
    +                    # FIXME: Need to consider temporary vs. permanent failures,
    
    993
    +                    #        and how this works with retries.
    
    994
    +                    except BstError as e:
    
    995
    +                        last_error = e
    
    996
    +                        continue
    
    999 997
     
    
    1000
    -            except StopIteration:
    
    1001
    -                pass
    
    998
    +                    # No error, we're done with this fetcher
    
    999
    +                    break
    
    1000
    +
    
    1001
    +                else:
    
    1002
    +                    # No break occurred, raise the last detected error
    
    1003
    +                    raise last_error
    
    1002 1004
     
    
    1003 1005
             # Default codepath is to reinstantiate the Source
    
    1004 1006
             #
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]