mirror of
				https://github.com/KevinMidboe/bulk-downloader-for-reddit.git
				synced 2025-10-29 17:40:15 +00:00 
			
		
		
		
	Improved exception handling
This commit is contained in:
		
							
								
								
									
										36
									
								
								script.py
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								script.py
									
									
									
									
									
								
							@@ -546,12 +546,26 @@ def download(submissions):
 | 
				
			|||||||
            sys.exit()
 | 
					            sys.exit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except ImgurLimitError as exception:
 | 
					        except ImgurLimitError as exception:
 | 
				
			||||||
            FAILED_FILE.add({int(i+1):[str(exception),submissions[i]]})
 | 
					            FAILED_FILE.add({int(i+1):[
 | 
				
			||||||
 | 
					                "{class_name}: {info}".format(
 | 
				
			||||||
 | 
					                    class_name=exception.__class__.__name__,info=str(exception)
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
 | 
					                submissions[i]
 | 
				
			||||||
 | 
					            ]})
 | 
				
			||||||
            downloadedCount -= 1
 | 
					            downloadedCount -= 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except NotADownloadableLinkError as exception:
 | 
					        except NotADownloadableLinkError as exception:
 | 
				
			||||||
            print(exception)
 | 
					            print(
 | 
				
			||||||
            FAILED_FILE.add({int(i+1):[str(exception),submissions[i]]})
 | 
					                "{class_name}: {info}".format(
 | 
				
			||||||
 | 
					                    class_name=exception.__class__.__name__,info=str(exception)
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            FAILED_FILE.add({int(i+1):[
 | 
				
			||||||
 | 
					                "{class_name}: {info}".format(
 | 
				
			||||||
 | 
					                    class_name=exception.__class__.__name__,info=str(exception)
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
 | 
					                submissions[i]
 | 
				
			||||||
 | 
					            ]})
 | 
				
			||||||
            downloadedCount -= 1
 | 
					            downloadedCount -= 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except NoSuitablePost:
 | 
					        except NoSuitablePost:
 | 
				
			||||||
@@ -560,8 +574,17 @@ def download(submissions):
 | 
				
			|||||||
        
 | 
					        
 | 
				
			||||||
        except Exception as exception:
 | 
					        except Exception as exception:
 | 
				
			||||||
            # raise exception
 | 
					            # raise exception
 | 
				
			||||||
            print(exception)
 | 
					            print(
 | 
				
			||||||
            FAILED_FILE.add({int(i+1):[str(exception),submissions[i]]})
 | 
					                "{class_name}: {info}".format(
 | 
				
			||||||
 | 
					                    class_name=exception.__class__.__name__,info=str(exception)
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            FAILED_FILE.add({int(i+1):[
 | 
				
			||||||
 | 
					                "{class_name}: {info}".format(
 | 
				
			||||||
 | 
					                    class_name=exception.__class__.__name__,info=str(exception)
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
 | 
					                submissions[i]
 | 
				
			||||||
 | 
					            ]})
 | 
				
			||||||
            downloadedCount -= 1
 | 
					            downloadedCount -= 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if duplicates:
 | 
					    if duplicates:
 | 
				
			||||||
@@ -587,9 +610,6 @@ def main():
 | 
				
			|||||||
        checkConflicts()
 | 
					        checkConflicts()
 | 
				
			||||||
    except ProgramModeError as err:
 | 
					    except ProgramModeError as err:
 | 
				
			||||||
        PromptUser()
 | 
					        PromptUser()
 | 
				
			||||||
    except Exception as err:
 | 
					 | 
				
			||||||
        print(err)
 | 
					 | 
				
			||||||
        sys.exit()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if not Path(GLOBAL.configDirectory).is_dir():
 | 
					    if not Path(GLOBAL.configDirectory).is_dir():
 | 
				
			||||||
        os.makedirs(GLOBAL.configDirectory)
 | 
					        os.makedirs(GLOBAL.configDirectory)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -139,9 +139,16 @@ class Erome:
 | 
				
			|||||||
                    howManyDownloaded -= 1
 | 
					                    howManyDownloaded -= 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                except Exception as exception:
 | 
					                except Exception as exception:
 | 
				
			||||||
                    raise exception
 | 
					                    # raise exception
 | 
				
			||||||
                    print("\n  Could not get the file")
 | 
					                    print("\n  Could not get the file")
 | 
				
			||||||
                    print("  " + str(exception) + "\n")
 | 
					                    print(
 | 
				
			||||||
 | 
					                        "  "
 | 
				
			||||||
 | 
					                        + "{class_name}: {info}".format(
 | 
				
			||||||
 | 
					                            class_name=exception.__class__.__name__,
 | 
				
			||||||
 | 
					                            info=str(exception)
 | 
				
			||||||
 | 
					                        )
 | 
				
			||||||
 | 
					                        + "\n"
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
                    exceptionType = exception
 | 
					                    exceptionType = exception
 | 
				
			||||||
                    howManyDownloaded -= 1
 | 
					                    howManyDownloaded -= 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -290,7 +297,14 @@ class Imgur:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                except Exception as exception:
 | 
					                except Exception as exception:
 | 
				
			||||||
                    print("\n  Could not get the file")
 | 
					                    print("\n  Could not get the file")
 | 
				
			||||||
                    print("  " + str(exception) + "\n")
 | 
					                    print(
 | 
				
			||||||
 | 
					                        "  "
 | 
				
			||||||
 | 
					                        + "{class_name}: {info}".format(
 | 
				
			||||||
 | 
					                            class_name=exception.__class__.__name__,
 | 
				
			||||||
 | 
					                            info=str(exception)
 | 
				
			||||||
 | 
					                        )
 | 
				
			||||||
 | 
					                        + "\n"
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
                    exceptionType = exception
 | 
					                    exceptionType = exception
 | 
				
			||||||
                    howManyDownloaded -= 1
 | 
					                    howManyDownloaded -= 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user