script stop on error

Hello,
I have some scripts on my router to collect bad IP addresses from multiple files
Unfortunately the scripts stop upon error.
The error in all cases is that IP already exists . The IP could have been imported from an earlier file.

The error displayed in the log :
“script error failure already have such entry”

There is no way that I can check every file for duplicated IP, my database has over 7000 black-listed IP.
I seek a solution to ignore the error and continue the script execution.
Thank you for your help.
My router OS version is 6.42.6

this is one of my scripts: They all look the same but the file name is different

:foreach i in=[/ip firewall address-list find ] do={
:if ( [/ip firewall address-list get $i comment] = “IPblacklist1” ) do={
/ip firewall address-list remove $i
}
}
/import file-name=IPblacklist1.rsc;
:log info “Removal old IPblacklist1 and add new”;

thank you in advance for your help

:do has an on-error feature. This should work:

:foreach i in=[/ip firewall address-list find ] do={
  :if ( [/ip firewall address-list get $i comment] = "IPblacklist1" ) do={
    :do {
      /ip firewall address-list remove $i
    } on-error={}
  }
}

You can try to catch and ignore the error.

https://wiki.mikrotik.com/wiki/Manual:Scripting#Catch_run-time_errors

It would look something like this.

:do {

:foreach i in=[/ip firewall address-list find ] do={
:if ( [/ip firewall address-list get $i comment] = "IPblacklist1" ) do={
/ip firewall address-list remove $i
}
}
/import file-name=IPblacklist1.rsc;
:log info "Removal old IPblacklist1 and add new";

} on-error={};

Hello
Thank you all for your assistance and interaction.
I still have the same issue

Thank you all, still having the same error
Failure: already have such entry

I even simplified the code
:do {
/ip firewall address-list remove [/ip firewall address-list find comment=ipblacklist1]
/import file-name=ipblacklist1.rsc;
:log info “Removal old ipblacklist1 and add new”;
} on-error={}

Even for fun I did this code , but I removed few entries to see if it wil work.still the same issue.
:do {
/import file-name=ipblacklist1.rsc;
:log info “Removal old ipblacklist1 and add new”;
} on-error={}


I appreciate if you could try and let me know what code will work.

Hello

It is a pity that I could not find a solution.
I had to rely on third party solution to do the job.
My problem is now temporarily solved.

the problem is inside “IPblacklist1.rsc”
can not add exist

you have 2 solution
remove all address list of “IPblacklist1” before import rsc file
or
you have to edit every line in rsc file like this example

:do {/ip firewall address-list
:do {add address=18.208.0.0/13 list=AWS comment="AWS-AMAZON"} on-error={}
:do {add address=52.95.245.0/24 list=AWS comment="AWS-AMAZON"} on-error={}
:do {add address=52.194.0.0/15 list=AWS comment="AWS-AMAZON"} on-error={}
:do {add address=54.155.0.0/16 list=AWS comment="AWS-AMAZON"} on-error={}